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(delivery): upsert and delete delivery configs through orca (spin…
- Loading branch information
Showing
7 changed files
with
316 additions
and
30 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
32 changes: 32 additions & 0 deletions
32
orca-front50/src/main/groovy/com/netflix/spinnaker/orca/front50/model/DeliveryConfig.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 @@ | ||
package com.netflix.spinnaker.orca.front50.model; | ||
|
||
import com.fasterxml.jackson.annotation.JsonAnyGetter; | ||
import com.fasterxml.jackson.annotation.JsonAnySetter; | ||
import lombok.Data; | ||
|
||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
@Data | ||
public class DeliveryConfig { | ||
private String id; | ||
private String application; | ||
private Long lastModified; | ||
private Long createTs; | ||
private String lastModifiedBy; | ||
private List<Map<String,Object>> deliveryArtifacts; | ||
private List<Map<String,Object>> deliveryEnvironments; | ||
|
||
private Map<String,Object> details = new HashMap<>(); | ||
|
||
@JsonAnyGetter | ||
Map<String,Object> details() { | ||
return details; | ||
} | ||
|
||
@JsonAnySetter | ||
void set(String name, Object value) { | ||
details.put(name, value); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
...rc/main/groovy/com/netflix/spinnaker/orca/front50/pipeline/DeleteDeliveryConfigStage.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,18 @@ | ||
package com.netflix.spinnaker.orca.front50.pipeline; | ||
|
||
import com.netflix.spinnaker.orca.front50.tasks.DeleteDeliveryConfigTask; | ||
import com.netflix.spinnaker.orca.pipeline.StageDefinitionBuilder; | ||
import com.netflix.spinnaker.orca.pipeline.TaskNode; | ||
import com.netflix.spinnaker.orca.pipeline.model.Stage; | ||
import org.springframework.stereotype.Component; | ||
|
||
import javax.annotation.Nonnull; | ||
|
||
@Component | ||
public class DeleteDeliveryConfigStage implements StageDefinitionBuilder { | ||
@Override | ||
public void taskGraph(@Nonnull Stage stage, @Nonnull TaskNode.Builder builder) { | ||
builder | ||
.withTask("deleteDeliveryConfig", DeleteDeliveryConfigTask.class); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
...rc/main/groovy/com/netflix/spinnaker/orca/front50/pipeline/UpsertDeliveryConfigStage.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,20 @@ | ||
package com.netflix.spinnaker.orca.front50.pipeline; | ||
|
||
import com.netflix.spinnaker.orca.front50.tasks.MonitorFront50Task; | ||
import com.netflix.spinnaker.orca.front50.tasks.UpsertDeliveryConfigTask; | ||
import com.netflix.spinnaker.orca.pipeline.StageDefinitionBuilder; | ||
import com.netflix.spinnaker.orca.pipeline.TaskNode; | ||
import com.netflix.spinnaker.orca.pipeline.model.Stage; | ||
import org.springframework.stereotype.Component; | ||
|
||
import javax.annotation.Nonnull; | ||
|
||
@Component | ||
public class UpsertDeliveryConfigStage implements StageDefinitionBuilder { | ||
@Override | ||
public void taskGraph(@Nonnull Stage stage, @Nonnull TaskNode.Builder builder) { | ||
builder | ||
.withTask("upsertDeliveryConfig", UpsertDeliveryConfigTask.class) | ||
.withTask("monitorUpsert", MonitorFront50Task.class); | ||
} | ||
} |
79 changes: 79 additions & 0 deletions
79
...50/src/main/groovy/com/netflix/spinnaker/orca/front50/tasks/DeleteDeliveryConfigTask.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,79 @@ | ||
package com.netflix.spinnaker.orca.front50.tasks; | ||
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.netflix.spinnaker.orca.ExecutionStatus; | ||
import com.netflix.spinnaker.orca.Task; | ||
import com.netflix.spinnaker.orca.TaskResult; | ||
import com.netflix.spinnaker.orca.front50.Front50Service; | ||
import com.netflix.spinnaker.orca.front50.model.DeliveryConfig; | ||
import com.netflix.spinnaker.orca.pipeline.model.Stage; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Component; | ||
import retrofit.RetrofitError; | ||
|
||
import javax.annotation.Nonnull; | ||
import java.util.Arrays; | ||
import java.util.Optional; | ||
|
||
@Component | ||
public class DeleteDeliveryConfigTask implements Task { | ||
|
||
private Logger log = LoggerFactory.getLogger(getClass()); | ||
|
||
private Front50Service front50Service; | ||
private ObjectMapper objectMapper; | ||
|
||
@Autowired | ||
public DeleteDeliveryConfigTask(Front50Service front50Service, ObjectMapper objectMapper) { | ||
this.front50Service = front50Service; | ||
this.objectMapper = objectMapper; | ||
} | ||
|
||
@Nonnull | ||
@Override | ||
public TaskResult execute(@Nonnull Stage stage) { | ||
StageData stageData = stage.mapTo(StageData.class); | ||
|
||
if (stageData.deliveryConfigId == null) { | ||
throw new IllegalArgumentException("Key 'deliveryConfigId' must be provided."); | ||
} | ||
|
||
Optional<DeliveryConfig> config = getDeliveryConfig(stageData.deliveryConfigId); | ||
|
||
if (!config.isPresent()) { | ||
log.debug("Config {} does not exist, considering deletion successful.", stageData.deliveryConfigId); | ||
return new TaskResult(ExecutionStatus.SUCCEEDED); | ||
} | ||
|
||
try { | ||
log.debug("Deleting delivery config: " + objectMapper.writeValueAsString(config.get())); | ||
} catch (JsonProcessingException e) { | ||
// ignore | ||
} | ||
|
||
front50Service.deleteDeliveryConfig(config.get().getApplication(), stageData.deliveryConfigId); | ||
|
||
return new TaskResult(ExecutionStatus.SUCCEEDED); | ||
} | ||
|
||
public Optional<DeliveryConfig> getDeliveryConfig(String id) { | ||
try { | ||
DeliveryConfig deliveryConfig = front50Service.getDeliveryConfig(id); | ||
return Optional.of(deliveryConfig); | ||
} catch (RetrofitError e) { | ||
//ignore an unknown (404) or unauthorized (403, 401) | ||
if (e.getResponse() != null && Arrays.asList(404, 403, 401).contains(e.getResponse().getStatus())) { | ||
return Optional.empty(); | ||
} else { | ||
throw e; | ||
} | ||
} | ||
} | ||
|
||
private static class StageData { | ||
public String deliveryConfigId; | ||
} | ||
} |
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
Oops, something went wrong.