Skip to content

Commit

Permalink
chore(spotless): upgrade spinnaker gradle plugin (#4757)
Browse files Browse the repository at this point in the history
This includes updates to google-java-format and ktlint, so requires some
formatting changes. These were made with a simple
`./gradlew spotlessApply`.
  • Loading branch information
plumpy committed Jul 27, 2020
1 parent f1d1b65 commit 3623583
Show file tree
Hide file tree
Showing 46 changed files with 353 additions and 239 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -199,22 +199,24 @@ class SqlProviderCache(private val backingStore: WriteableCache) : ProviderCache
// Update resource table from Authoritative sources only
when {
// OnDemand agents should only be treated as authoritative and don't use standard eviction logic
source.contains(ON_DEMAND.ns, ignoreCase = true) -> cacheResult.cacheResults
// And OnDemand agents shouldn't update other resource type tables
.filter {
it.key.contains(ON_DEMAND.ns, ignoreCase = true)
}
.forEach {
cacheDataType(it.key, source, it.value, authoritative = true, cleanup = false)
}
authoritativeTypes.isNotEmpty() -> cacheResult.cacheResults
.filter {
authoritativeTypes.contains(it.key)
}
.forEach {
cacheDataType(it.key, source, it.value, authoritative = true)
cachedTypes.add(it.key)
}
source.contains(ON_DEMAND.ns, ignoreCase = true) ->
cacheResult.cacheResults
// And OnDemand agents shouldn't update other resource type tables
.filter {
it.key.contains(ON_DEMAND.ns, ignoreCase = true)
}
.forEach {
cacheDataType(it.key, source, it.value, authoritative = true, cleanup = false)
}
authoritativeTypes.isNotEmpty() ->
cacheResult.cacheResults
.filter {
authoritativeTypes.contains(it.key)
}
.forEach {
cacheDataType(it.key, source, it.value, authoritative = true)
cachedTypes.add(it.key)
}
else -> // If there are no authoritative types in cacheResult, override all as authoritative without cleanup
cacheResult.cacheResults
.forEach {
Expand All @@ -240,7 +242,7 @@ class SqlProviderCache(private val backingStore: WriteableCache) : ProviderCache
}
}
} finally {
MDC.remove("agentClass")
MDC.remove("agentClass")
}
}

Expand Down Expand Up @@ -271,7 +273,7 @@ class SqlProviderCache(private val backingStore: WriteableCache) : ProviderCache
cacheDataType(it.key, source, it.value, authoritative = false, cleanup = false)
}
} finally {
MDC.remove("agentClass")
MDC.remove("agentClass")
}
}

Expand All @@ -280,7 +282,7 @@ class SqlProviderCache(private val backingStore: WriteableCache) : ProviderCache
MDC.put("agentClass", "putCacheData")
backingStore.merge(type, cacheData)
} finally {
MDC.remove("agentClass")
MDC.remove("agentClass")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,10 @@ class SqlCache(
private const val onDemandType = "onDemand"

private val schemaVersion = SqlSchemaVersion.current()
private val useRegexp = """.*[\?\[].*""".toRegex()
private val cleanRegexp = """\.+\*""".toRegex()
private val useRegexp =
""".*[\?\[].*""".toRegex()
private val cleanRegexp =
"""\.+\*""".toRegex()

private val log = LoggerFactory.getLogger(SqlCache::class.java)
}
Expand Down Expand Up @@ -852,10 +854,14 @@ class SqlCache(
if (!createdTables.contains(type)) {
try {
withRetry(RetryCategory.WRITE) {
jooq.execute("CREATE TABLE IF NOT EXISTS ${sqlNames.resourceTableName(type)} " +
"LIKE cats_v${schemaVersion}_resource_template")
jooq.execute("CREATE TABLE IF NOT EXISTS ${sqlNames.relTableName(type)} " +
"LIKE cats_v${schemaVersion}_rel_template")
jooq.execute(
"CREATE TABLE IF NOT EXISTS ${sqlNames.resourceTableName(type)} " +
"LIKE cats_v${schemaVersion}_resource_template"
)
jooq.execute(
"CREATE TABLE IF NOT EXISTS ${sqlNames.relTableName(type)} " +
"LIKE cats_v${schemaVersion}_rel_template"
)
}

createdTables.add(type)
Expand All @@ -867,10 +873,14 @@ class SqlCache(
// TODO not sure if best schema for onDemand
try {
withRetry(RetryCategory.WRITE) {
jooq.execute("CREATE TABLE IF NOT EXISTS ${sqlNames.resourceTableName(onDemandType)} " +
"LIKE cats_v${schemaVersion}_resource_template")
jooq.execute("CREATE TABLE IF NOT EXISTS ${sqlNames.relTableName(onDemandType)} " +
"LIKE cats_v${schemaVersion}_rel_template")
jooq.execute(
"CREATE TABLE IF NOT EXISTS ${sqlNames.resourceTableName(onDemandType)} " +
"LIKE cats_v${schemaVersion}_resource_template"
)
jooq.execute(
"CREATE TABLE IF NOT EXISTS ${sqlNames.relTableName(onDemandType)} " +
"LIKE cats_v${schemaVersion}_rel_template"
)
}

createdTables.add(onDemandType)
Expand Down Expand Up @@ -1136,8 +1146,8 @@ class SqlCache(
relationshipPrefixes: List<String>
):
DataWithRelationshipPointersResult {
return getDataWithRelationships(type, emptyList(), relationshipPrefixes)
}
return getDataWithRelationships(type, emptyList(), relationshipPrefixes)
}

private fun getDataWithRelationships(
type: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ class SqlNames(

companion object {
private val schemaVersion = SqlSchemaVersion.current()
private val typeSanitization = """[^A-Za-z0-9_]""".toRegex()
private val typeSanitization =
"""[^A-Za-z0-9_]""".toRegex()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ enum class SqlSchemaVersion(val version: Int) {
V1(1);

companion object {
fun current(): Int = V1.version
fun current(): Int = V1.version
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -185,12 +185,17 @@ class SqlClusteredAgentScheduler(
if (now > existingLocks.getLong("lock_expiry")) {
try {
jooq.deleteFrom(table(lockTable))
.where(field("agent_name").eq(existingLocks.getString("agent_name"))
.and(field("lock_expiry").eq(existingLocks.getString("lock_expiry"))))
.where(
field("agent_name").eq(existingLocks.getString("agent_name"))
.and(field("lock_expiry").eq(existingLocks.getString("lock_expiry")))
)
.execute()
} catch (e: SQLException) {
log.error("Failed deleting agent lock ${existingLocks.getString("agent_name")} with expiry " +
existingLocks.getString("lock_expiry"), e)
log.error(
"Failed deleting agent lock ${existingLocks.getString("agent_name")} with expiry " +
existingLocks.getString("lock_expiry"),
e
)

candidateAgentLocks.remove(existingLocks.getString("agent_name"))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,12 @@ import org.springframework.context.annotation.Configuration
class SqlAgentSchedulerConfiguration {

@Bean
@ConditionalOnProperty(value = [
"sql.enabled",
"sql.scheduler.enabled"
])
@ConditionalOnProperty(
value = [
"sql.enabled",
"sql.scheduler.enabled"
]
)
fun sqlAgentScheduler(
jooq: DSLContext,
agentIntervalProvider: AgentIntervalProvider,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,18 @@ class SqlNamesTest : JUnit5Minutests {
listOf(
Pair(null, null),
Pair("myagent", "myagent"),
Pair("abcdefghij".repeat(20),
"abcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdebb43b982e477772faa2e899f65d0a86b"),
Pair("abcdefghij".repeat(10) + ":" + "abcdefghij".repeat(10),
"abcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghij:20f5a9d8d3f4f18cfec8a40eda"),
Pair("abcdefghij:" + "abcdefghij".repeat(20),
"abcdefghij:abcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcd5bfa5c163877f247769cd6b488dff339")
Pair(
"abcdefghij".repeat(20),
"abcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdebb43b982e477772faa2e899f65d0a86b"
),
Pair(
"abcdefghij".repeat(10) + ":" + "abcdefghij".repeat(10),
"abcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghij:20f5a9d8d3f4f18cfec8a40eda"
),
Pair(
"abcdefghij:" + "abcdefghij".repeat(20),
"abcdefghij:abcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcd5bfa5c163877f247769cd6b488dff339"
)
).forEach { test ->
test("max length of table name is checked: ${test.first}") {
expectThat(checkAgentName(test.first))
Expand All @@ -66,8 +72,10 @@ class SqlNamesTest : JUnit5Minutests {

test("do not accept types that are too long") {
expect {
that(kotlin.runCatching { checkAgentName("abcdefghij".repeat(20) + ":abcdefghij") }
.exceptionOrNull()).isA<IllegalArgumentException>()
that(
kotlin.runCatching { checkAgentName("abcdefghij".repeat(20) + ":abcdefghij") }
.exceptionOrNull()
).isA<IllegalArgumentException>()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,12 @@ class SqlUnknownAgentCleanupAgentTest : JUnit5Minutests {

context("test and prod accounts exist") {
deriveFixture {
fixture.providerAgents.addAll(listOf(
testCachingAgent(),
prodCachingAgent()
))
fixture.providerAgents.addAll(
listOf(
testCachingAgent(),
prodCachingAgent()
)
)
seedDatabase(includeTestAccount = true, includeProdAccount = true)
fixture
}
Expand Down Expand Up @@ -211,15 +213,15 @@ class SqlUnknownAgentCleanupAgentTest : JUnit5Minutests {
it.authoritative = setOf(INSTANCES.ns)
it.results = mapOf(
INSTANCES.ns to listOf(
DefaultCacheData(
"aws:instances:test:us-east-1:i-abcd1234",
mapOf(),
mapOf(
SERVER_GROUPS.ns to listOf(
"aws:serverGroups:myapp-test:test:us-east-1:myapp-test-v000"
)
)
)
DefaultCacheData(
"aws:instances:test:us-east-1:i-abcd1234",
mapOf(),
mapOf(
SERVER_GROUPS.ns to listOf(
"aws:serverGroups:myapp-test:test:us-east-1:myapp-test-v000"
)
)
)
)
)
}
Expand All @@ -231,15 +233,15 @@ class SqlUnknownAgentCleanupAgentTest : JUnit5Minutests {
it.authoritative = setOf(INSTANCES.ns)
it.results = mapOf(
INSTANCES.ns to listOf(
DefaultCacheData(
"aws:instances:prod:us-east-1:i-abcd1234",
mapOf(),
mapOf(
SERVER_GROUPS.ns to listOf(
"aws:serverGroups:myapp-prod:prod:us-east-1:myapp-prod-v000"
)
)
)
DefaultCacheData(
"aws:instances:prod:us-east-1:i-abcd1234",
mapOf(),
mapOf(
SERVER_GROUPS.ns to listOf(
"aws:serverGroups:myapp-prod:prod:us-east-1:myapp-prod-v000"
)
)
)
)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,17 @@ void schedule(
AgentExecution agentExecution,
ExecutionInstrumentation executionInstrumentation);

default void unschedule(Agent agent) {};
default void unschedule(Agent agent) {}
;

/**
* @return True iff this scheduler supports synchronization between LoadData and OnDemand cache
* updates.
*/
default boolean isAtomic() {
return false;
};
}
;

/**
* @param agent The agent being locked.
Expand All @@ -43,21 +45,24 @@ default boolean isAtomic() {
*/
default T tryLock(Agent agent) {
return null;
};
}
;

/**
* @param lock The lock being released.
* @return True iff the lock was still in our possession when the release call was made.
*/
default boolean tryRelease(T lock) {
return false;
};
}
;

/**
* @param lock The lock being checked for validity.
* @return True iff the lock is still in our possession.
*/
default boolean lockValid(T lock) {
return false;
};
}
;
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,12 @@ public abstract class AgentSchedulerAware {
/** Set this object's agent scheduler. */
public void setAgentScheduler(AgentScheduler agentScheduler) {
this.agentScheduler = agentScheduler;
};
}
;

/** Get this object's agent scheduler. */
public AgentScheduler getAgentScheduler() {
return agentScheduler;
};
}
;
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ public class GcsStorageService {

public static interface VisitorOperation {
void visit(StorageObject storageObj) throws IOException;
};
}
;

public static class Factory {
private String applicationName_;
Expand Down Expand Up @@ -92,7 +93,8 @@ private GoogleCredentials loadCredentials(String credentialsPath) throws IOExcep
}
return credentials;
}
};
}
;

private Storage storage_;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,8 @@ public void run() {
.describeSecurityGroups(
new DescribeSecurityGroupsRequest()
.withFilters(new Filter("vpc-id").withValues(classicLinkVpcId)))
.getSecurityGroups().stream()
.getSecurityGroups()
.stream()
.collect(Collectors.toMap(SecurityGroup::getGroupName, SecurityGroup::getGroupId));

reconcileInstances(ec2, groupNamesToIds, classicLinkInstances.values());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,8 @@ private boolean stackExists(AmazonCloudFormation amazonCloudFormation) {
private String getStackId(AmazonCloudFormation amazonCloudFormation) {
return amazonCloudFormation
.describeStacks(new DescribeStacksRequest().withStackName(description.getStackName()))
.getStacks().stream()
.getStacks()
.stream()
.findFirst()
.orElseThrow(
() ->
Expand Down
Loading

0 comments on commit 3623583

Please sign in to comment.