Skip to content

Commit

Permalink
feat(core): Genericize execution migrators (#2355)
Browse files Browse the repository at this point in the history
Squashes PollingAgentExecutionRepository methods into the
root ExecutionRepository interface. This separatino was more
pain that it was worth.

Pulled forward the DualExecutionRepository that was written
for Orca SQL into orca-core.

For the main show, I've refactored the two execution data
migrators so that they're persistence backend agnostic.
Combined with DualExecutionRepository, you can migrate from
one backend to another without writing new migration logic,
making the operational story a little simpler for an already
tough process.
  • Loading branch information
robzienert committed Aug 9, 2018
1 parent b39e74f commit 608efe5
Show file tree
Hide file tree
Showing 20 changed files with 578 additions and 436 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -534,5 +534,39 @@ abstract class ExecutionRepositoryTck<T extends ExecutionRepository> extends Spe
[RUNNING, SUCCEEDED] | 1 | PIPELINE | 1
[RUNNING, SUCCEEDED] | 1 | ORCHESTRATION | 1
}

def "can retrieve all application names in database, type: #executionType, min: #minExecutions"() {
given:
def execution1 = pipeline {
application = "spindemo"
}
def execution2 = pipeline {
application = "orca"
}
def execution3 = orchestration {
application = "spindemo"
}
def execution4 = orchestration {
application = "spindemo"
}

when:
repository.store(execution1)
repository.store(execution2)
repository.store(execution3)
repository.store(execution4)
def apps = repository.retrieveAllApplicationNames(executionType, minExecutions)

then:
apps.sort() == expectedApps.sort()

where:
executionType | minExecutions || expectedApps
ORCHESTRATION | 0 || ["spindemo"]
PIPELINE | 0 || ["spindemo", "orca"]
null | 0 || ["spindemo", "orca"]
null | 2 || ["spindemo"]
PIPELINE | 2 || []
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.netflix.spinnaker.orca.notifications.AbstractPollingNotificationAgent;
import com.netflix.spinnaker.orca.notifications.NotificationClusterLock;
import com.netflix.spinnaker.orca.pipeline.model.Execution;
import com.netflix.spinnaker.orca.pipeline.persistence.ExecutionRepository;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -83,7 +84,7 @@ public Boolean call(Execution execution) {
};

private final Clock clock;
private final PollingAgentExecutionRepository executionRepository;
private final ExecutionRepository executionRepository;
private final Registry registry;

private final long pollingIntervalMs;
Expand All @@ -95,7 +96,7 @@ public Boolean call(Execution execution) {

@Autowired
public OldPipelineCleanupPollingNotificationAgent(NotificationClusterLock clusterLock,
PollingAgentExecutionRepository executionRepository,
ExecutionRepository executionRepository,
Clock clock,
Registry registry,
@Value("${pollers.oldPipelineCleanup.intervalMs:3600000}") long pollingIntervalMs,
Expand Down Expand Up @@ -169,7 +170,7 @@ private void cleanup(List<PipelineExecutionDetails> executions) {
executions.subList(0, (executions.size() - minimumPipelineExecutions)).forEach(p -> {
long startTime = p.startTime == null ? p.buildTime : p.startTime;
long days = ChronoUnit.DAYS.between(Instant.ofEpochMilli(startTime), Instant.ofEpochMilli(clock.millis()));
if (days > thresholdDays && !executionRepository.hasEntityTags(PIPELINE, p.id)) {
if (days > thresholdDays) {
log.info("Deleting pipeline execution " + p.id + ": " + p.toString());
registry.counter(deletedId.withTag("application", p.application)).increment();
executionRepository.delete(PIPELINE, p.id);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.netflix.spinnaker.orca.notifications.AbstractPollingNotificationAgent;
import com.netflix.spinnaker.orca.notifications.NotificationClusterLock;
import com.netflix.spinnaker.orca.pipeline.model.Execution;
import com.netflix.spinnaker.orca.pipeline.persistence.ExecutionRepository;
import com.netflix.spinnaker.orca.pipeline.persistence.ExecutionRepository.ExecutionCriteria;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -66,7 +67,7 @@ public class TopApplicationExecutionCleanupPollingNotificationAgent extends Abst
return builder;
};

private final PollingAgentExecutionRepository executionRepository;
private final ExecutionRepository executionRepository;
private final Registry registry;
private final long pollingIntervalMs;
private final int threshold;
Expand All @@ -76,7 +77,7 @@ public class TopApplicationExecutionCleanupPollingNotificationAgent extends Abst

@Autowired
public TopApplicationExecutionCleanupPollingNotificationAgent(NotificationClusterLock clusterLock,
PollingAgentExecutionRepository executionRepository,
ExecutionRepository executionRepository,
Registry registry,
@Value("${pollers.topApplicationExecutionCleanup.intervalMs:3600000}") long pollingIntervalMs,
@Value("${pollers.topApplicationExecutionCleanup.threshold:2500}") int threshold) {
Expand Down
Loading

0 comments on commit 608efe5

Please sign in to comment.