Skip to content

Commit

Permalink
feat(cf): Add Sharing / Unsharing of services (#2750)
Browse files Browse the repository at this point in the history
- 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
2 people authored and jkschneider committed Mar 13, 2019
1 parent 808f7fd commit ab75780
Show file tree
Hide file tree
Showing 33 changed files with 1,021 additions and 648 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import com.netflix.spinnaker.orca.clouddriver.pipeline.servicebroker.DestroyServiceStagePreprocessor;
import com.netflix.spinnaker.orca.clouddriver.tasks.providers.cf.CloudFoundryDestroyServiceTask;
import com.netflix.spinnaker.orca.clouddriver.tasks.providers.cf.CloudFoundryMonitorKatoServicesTask;
import com.netflix.spinnaker.orca.clouddriver.tasks.providers.cf.CloudFoundryWaitForDeployServiceTask;
import com.netflix.spinnaker.orca.clouddriver.tasks.providers.cf.CloudFoundryWaitForDestroyServiceTask;
import com.netflix.spinnaker.orca.kato.pipeline.support.StageData;
import com.netflix.spinnaker.orca.pipeline.TaskNode;
Expand Down
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);
}
}
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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,28 @@

package com.netflix.spinnaker.orca.clouddriver.pipeline.servicebroker;

import com.netflix.spinnaker.orca.clouddriver.pipeline.AbstractCloudProviderAwareStage;
import com.netflix.spinnaker.orca.clouddriver.pipeline.servicebroker.DeployServiceStagePreprocessor;
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 groovy.transform.CompileStatic;
import org.springframework.beans.factory.annotation.Autowired;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Component;

import javax.annotation.Nonnull;
import java.util.ArrayList;
import java.util.List;

@AllArgsConstructor
@Component
class DeployServiceStage extends AbstractCloudProviderAwareStage {
class DeployServiceStage implements StageDefinitionBuilder, CloudProviderAware {
public static final String PIPELINE_CONFIG_TYPE = "deployService";

@Autowired(required = false)
List<DeployServiceStagePreprocessor> deployServiceStagePreprocessors = new ArrayList<>();

public DeployServiceStage() {
super(PIPELINE_CONFIG_TYPE);
@Nonnull
@Override
public String getType() {
return PIPELINE_CONFIG_TYPE;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,28 @@

package com.netflix.spinnaker.orca.clouddriver.pipeline.servicebroker;

import com.netflix.spinnaker.orca.clouddriver.pipeline.AbstractCloudProviderAwareStage;
import com.netflix.spinnaker.orca.clouddriver.pipeline.servicebroker.DestroyServiceStagePreprocessor;
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 groovy.transform.CompileStatic;
import org.springframework.beans.factory.annotation.Autowired;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Component;

import javax.annotation.Nonnull;
import java.util.ArrayList;
import java.util.List;

@AllArgsConstructor
@Component
class DestroyServiceStage extends AbstractCloudProviderAwareStage {
class DestroyServiceStage implements StageDefinitionBuilder, CloudProviderAware {
public static final String PIPELINE_CONFIG_TYPE = "destroyService";

@Autowired(required = false)
List<DestroyServiceStagePreprocessor> destroyServiceStagePreprocessors = new ArrayList<>();

public DestroyServiceStage() {
super(PIPELINE_CONFIG_TYPE);
@Nonnull
@Override
public String getType() {
return PIPELINE_CONFIG_TYPE;
}

@Override
Expand Down
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));
}
}
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);
}
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));
}
}
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);
}
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);
}
}
Loading

0 comments on commit ab75780

Please sign in to comment.