forked from spinnaker/orca
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(alibabacloud): add a new provider of alicloud (spinnaker#3055)
- Loading branch information
1 parent
48e545b
commit 4963dc2
Showing
6 changed files
with
287 additions
and
1 deletion.
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
101 changes: 101 additions & 0 deletions
101
...ix/spinnaker/orca/clouddriver/tasks/providers/alicloud/AliCloudSecurityGroupUpserter.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,101 @@ | ||
/* | ||
* Copyright 2019 Alibaba Group. | ||
* | ||
* 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.alicloud; | ||
|
||
import com.netflix.spinnaker.orca.clouddriver.MortService; | ||
import com.netflix.spinnaker.orca.clouddriver.MortService.SecurityGroup; | ||
import com.netflix.spinnaker.orca.clouddriver.tasks.securitygroup.SecurityGroupUpserter; | ||
import com.netflix.spinnaker.orca.clouddriver.utils.CloudProviderAware; | ||
import com.netflix.spinnaker.orca.pipeline.model.Stage; | ||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class AliCloudSecurityGroupUpserter implements SecurityGroupUpserter, CloudProviderAware { | ||
|
||
final String cloudProvider = "alicloud"; | ||
|
||
@Autowired MortService mortService; | ||
|
||
@Override | ||
public OperationContext getOperationContext(Stage stage) { | ||
SecurityGroupUpserter.OperationContext operationContext = | ||
new SecurityGroupUpserter.OperationContext(); | ||
Map<String, Object> context = stage.getContext(); | ||
Map<String, Object> extraOutput = new HashMap(30); | ||
String name = (String) context.get("securityGroupName"); | ||
String vpcId = (String) context.get("vpcId"); | ||
Object securityGroupIngress = context.get("securityGroupIngress"); | ||
List<Map> list = new ArrayList<>(); | ||
List<MortService.SecurityGroup> targets = new ArrayList<>(); | ||
List<String> regions = new ArrayList<>(); | ||
if (context.get("regions") != null) { | ||
regions.addAll((List) context.get("regions")); | ||
} else { | ||
if (context.get("region") != null) { | ||
regions.add((String) context.get("region")); | ||
} | ||
} | ||
for (String region : regions) { | ||
Map<String, Object> map = new HashMap(16); | ||
Map<String, Object> operation = new HashMap(50); | ||
MortService.SecurityGroup securityGroup = new MortService.SecurityGroup(); | ||
securityGroup.setAccountName(getCredentials(stage)); | ||
securityGroup.setRegion(region); | ||
securityGroup.setName(name); | ||
securityGroup.setVpcId(vpcId); | ||
targets.add(securityGroup); | ||
operation.putAll(context); | ||
operation.put("region", region); | ||
map.put(SecurityGroupUpserter.OPERATION, operation); | ||
list.add(map); | ||
} | ||
extraOutput.put("targets", targets); | ||
extraOutput.put("securityGroupIngress", securityGroupIngress); | ||
operationContext.setOperations(list); | ||
operationContext.setExtraOutput(extraOutput); | ||
return operationContext; | ||
} | ||
|
||
@Override | ||
public boolean isSecurityGroupUpserted(SecurityGroup upsertedSecurityGroup, Stage stage) { | ||
if (upsertedSecurityGroup == null) { | ||
return false; | ||
} | ||
SecurityGroup securityGroup = | ||
mortService.getSecurityGroup( | ||
upsertedSecurityGroup.getAccountName(), | ||
cloudProvider, | ||
upsertedSecurityGroup.getName(), | ||
upsertedSecurityGroup.getRegion(), | ||
upsertedSecurityGroup.getVpcId()); | ||
|
||
if (upsertedSecurityGroup.getName().equals(securityGroup.getName())) { | ||
return true; | ||
} else { | ||
return false; | ||
} | ||
} | ||
|
||
@Override | ||
public String getCloudProvider() { | ||
return cloudProvider; | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
...tflix/spinnaker/orca/clouddriver/tasks/providers/alicloud/AliCloudServerGroupCreator.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,61 @@ | ||
/* | ||
* Copyright 2019 Alibaba Group. | ||
* | ||
* 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.alicloud; | ||
|
||
import com.netflix.spinnaker.orca.clouddriver.tasks.servergroup.ServerGroupCreator; | ||
import com.netflix.spinnaker.orca.pipeline.model.Stage; | ||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class AliCloudServerGroupCreator implements ServerGroupCreator { | ||
|
||
final String cloudProvider = "alicloud"; | ||
|
||
@Override | ||
public List<Map> getOperations(Stage stage) { | ||
List<Map> list = new ArrayList<>(); | ||
Map<String, Object> map = new HashMap(16); | ||
Map<String, Object> operation = new HashMap(50); | ||
operation.putAll(stage.getContext()); | ||
if (stage.getContext().get("account") != null | ||
&& stage.getContext().get("credentials") == null) { | ||
operation.put("credentials", stage.getContext().get("account")); | ||
} | ||
map.put(ServerGroupCreator.OPERATION, operation); | ||
list.add(map); | ||
return list; | ||
} | ||
|
||
@Override | ||
public boolean isKatoResultExpected() { | ||
return false; | ||
} | ||
|
||
@Override | ||
public String getCloudProvider() { | ||
return cloudProvider; | ||
} | ||
|
||
@Override | ||
public Optional<String> getHealthProviderName() { | ||
return Optional.of("AliCloud"); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
...ver/src/main/groovy/com/netflix/spinnaker/orca/kato/pipeline/ModifyScalingGroupStage.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,34 @@ | ||
/* | ||
* Copyright 2019 Alibaba Group. | ||
* | ||
* 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.kato.pipeline; | ||
|
||
import com.netflix.spinnaker.orca.kato.tasks.ModifyScalingGroupTask; | ||
import com.netflix.spinnaker.orca.pipeline.StageDefinitionBuilder; | ||
import com.netflix.spinnaker.orca.pipeline.TaskNode.Builder; | ||
import com.netflix.spinnaker.orca.pipeline.model.Stage; | ||
import groovy.transform.CompileStatic; | ||
import javax.annotation.Nonnull; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
@CompileStatic | ||
public class ModifyScalingGroupStage implements StageDefinitionBuilder { | ||
|
||
@Override | ||
public void taskGraph(@Nonnull Stage stage, @Nonnull Builder builder) { | ||
builder.withTask("modifyScalingGroup", ModifyScalingGroupTask.class); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
...oovy/com/netflix/spinnaker/orca/kato/pipeline/support/ScalingGroupDescriptionSupport.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 Alibaba Group. | ||
* | ||
* 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.kato.pipeline.support; | ||
|
||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
public class ScalingGroupDescriptionSupport { | ||
|
||
public static Map convertScalingGroupToDeploymentTargets( | ||
List<Map<String, String>> scalingGroups) { | ||
Map<String, Object> deployServerGroups = new HashMap<>(16); | ||
for (Map<String, String> scalingGroup : scalingGroups) { | ||
deployServerGroups.put(scalingGroup.get("region"), scalingGroup.get("scalingGroupName")); | ||
} | ||
return deployServerGroups; | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
...ddriver/src/main/groovy/com/netflix/spinnaker/orca/kato/tasks/ModifyScalingGroupTask.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,58 @@ | ||
/* | ||
* Copyright 2019 Alibaba Group. | ||
* | ||
* 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.kato.tasks; | ||
|
||
import com.google.common.collect.ImmutableMap; | ||
import com.netflix.spinnaker.orca.ExecutionStatus; | ||
import com.netflix.spinnaker.orca.Task; | ||
import com.netflix.spinnaker.orca.TaskResult; | ||
import com.netflix.spinnaker.orca.clouddriver.KatoService; | ||
import com.netflix.spinnaker.orca.kato.pipeline.support.ScalingGroupDescriptionSupport; | ||
import com.netflix.spinnaker.orca.pipeline.model.Stage; | ||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import javax.annotation.Nonnull; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class ModifyScalingGroupTask implements Task { | ||
|
||
@Autowired KatoService kato; | ||
|
||
@Nonnull | ||
@Override | ||
public TaskResult execute(@Nonnull Stage stage) { | ||
List list = new ArrayList<>(); | ||
Map<String, Map> objectMap = new HashMap<>(16); | ||
Map<String, Object> context = stage.getContext(); | ||
objectMap.put("modifyScalingGroupDescription", context); | ||
list.add(objectMap); | ||
Object taskId = kato.requestOperations(list).toBlocking().first(); | ||
List<Map<String, String>> scalingGroups = (List) context.get("scalingGroups"); | ||
Map deployServerGroups = | ||
ScalingGroupDescriptionSupport.convertScalingGroupToDeploymentTargets(scalingGroups); | ||
Map<String, Object> result = | ||
new ImmutableMap.Builder<String, Object>() | ||
.put("notification.type", "modifyScalingGroup") | ||
.put("deploy.server.groups", deployServerGroups) | ||
.put("kato.last.task.id", taskId) | ||
.build(); | ||
return TaskResult.builder(ExecutionStatus.SUCCEEDED).context(result).build(); | ||
} | ||
} |