diff --git a/orca-core/src/main/java/com/netflix/spinnaker/orca/pipeline/model/NexusTrigger.kt b/orca-core/src/main/java/com/netflix/spinnaker/orca/pipeline/model/NexusTrigger.kt new file mode 100644 index 0000000000..5738a1acf3 --- /dev/null +++ b/orca-core/src/main/java/com/netflix/spinnaker/orca/pipeline/model/NexusTrigger.kt @@ -0,0 +1,37 @@ +/* + * 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.pipeline.model + +import com.netflix.spinnaker.kork.artifacts.model.Artifact +import com.netflix.spinnaker.kork.artifacts.model.ExpectedArtifact + +data class NexusTrigger +@JvmOverloads constructor( + override val type: String = "nexus", + override val correlationId: String? = null, + override val user: String? = "[anonymous]", + override val parameters: Map = mutableMapOf(), + override val artifacts: List = mutableListOf(), + override val notifications: List> = mutableListOf(), + override var isRebake: Boolean = false, + override var isDryRun: Boolean = false, + override var isStrategy: Boolean = false, + val nexusSearchName: String +) : Trigger { + override var other: Map = mutableMapOf() + override var resolvedExpectedArtifacts: List = mutableListOf() +} diff --git a/orca-core/src/main/java/com/netflix/spinnaker/orca/pipeline/model/support/TriggerDeserializer.kt b/orca-core/src/main/java/com/netflix/spinnaker/orca/pipeline/model/support/TriggerDeserializer.kt index 886535eb34..acdf35ad9e 100644 --- a/orca-core/src/main/java/com/netflix/spinnaker/orca/pipeline/model/support/TriggerDeserializer.kt +++ b/orca-core/src/main/java/com/netflix/spinnaker/orca/pipeline/model/support/TriggerDeserializer.kt @@ -27,6 +27,7 @@ import com.netflix.spinnaker.orca.pipeline.model.DockerTrigger import com.netflix.spinnaker.orca.pipeline.model.Execution import com.netflix.spinnaker.orca.pipeline.model.GitTrigger import com.netflix.spinnaker.orca.pipeline.model.JenkinsTrigger +import com.netflix.spinnaker.orca.pipeline.model.NexusTrigger import com.netflix.spinnaker.orca.pipeline.model.PipelineTrigger import com.netflix.spinnaker.orca.pipeline.model.Trigger @@ -111,6 +112,18 @@ internal class TriggerDeserializer : get("strategy")?.booleanValue() == true, get("artifactorySearchName").textValue() ) + looksLikeNexus() -> NexusTrigger( + get("type").textValue(), + get("correlationId")?.textValue(), + get("user")?.textValue() ?: "[anonymous]", + get("parameters")?.mapValue(parser) ?: mutableMapOf(), + get("artifacts")?.listValue(parser) ?: mutableListOf(), + get("notifications")?.listValue(parser) ?: mutableListOf(), + get("rebake")?.booleanValue() == true, + get("dryRun")?.booleanValue() == true, + get("strategy")?.booleanValue() == true, + get("nexusSearchName").textValue() + ) looksLikeGit() -> GitTrigger( get("type").textValue(), get("correlationId")?.textValue(), @@ -166,6 +179,9 @@ internal class TriggerDeserializer : private fun JsonNode.looksLikeArtifactory() = hasNonNull("artifactorySearchName") + private fun JsonNode.looksLikeNexus() = + hasNonNull("nexusSearchName") + private fun JsonNode.looksLikeCustom() = customTriggerSuppliers.any { it.predicate.invoke(this) } diff --git a/orca-core/src/test/groovy/com/netflix/spinnaker/orca/pipeline/model/TriggerSpec.groovy b/orca-core/src/test/groovy/com/netflix/spinnaker/orca/pipeline/model/TriggerSpec.groovy index 375a09e57d..674d3146a8 100644 --- a/orca-core/src/test/groovy/com/netflix/spinnaker/orca/pipeline/model/TriggerSpec.groovy +++ b/orca-core/src/test/groovy/com/netflix/spinnaker/orca/pipeline/model/TriggerSpec.groovy @@ -494,6 +494,31 @@ class TriggerSpec extends Specification { ''' } + def "can parse an nexus trigger"() { + given: + def trigger = mapper.readValue(triggerJson, Trigger) + + expect: + trigger instanceof NexusTrigger + with(trigger) { + nexusSearchName == "search-name" + } + + where: + triggerJson = ''' +{ + "account": "theaccount", + "enabled": true, + "job": "the-job", + "master": "master", + "organization": "org", + "nexusSearchName": "search-name", + "nexusRepository": "libs-demo-local", + "type": "nexus" +} +''' + } + def pubSubTrigger = ''' { "attributeConstraints": { diff --git a/orca-web/src/test/groovy/com/netflix/spinnaker/orca/controllers/TaskControllerSpec.groovy b/orca-web/src/test/groovy/com/netflix/spinnaker/orca/controllers/TaskControllerSpec.groovy index 7c5293197d..e75165a3a5 100644 --- a/orca-web/src/test/groovy/com/netflix/spinnaker/orca/controllers/TaskControllerSpec.groovy +++ b/orca-web/src/test/groovy/com/netflix/spinnaker/orca/controllers/TaskControllerSpec.groovy @@ -378,6 +378,9 @@ class TaskControllerSpec extends Specification { ], [pipelineConfigId: "1", id: "test-4", startTime: clock.instant().minus(daysOfExecutionHistory, DAYS).minus(2, HOURS).toEpochMilli(), trigger: new ArtifactoryTrigger("libs-demo-local") + ], + [pipelineConfigId: "1", id: "test-5", startTime: clock.instant().minus(daysOfExecutionHistory, DAYS).minus(2, HOURS).toEpochMilli(), + trigger: new NexusTrigger("libs-nexus-local") ] ] @@ -405,7 +408,7 @@ class TaskControllerSpec extends Specification { List results = new ObjectMapper().readValue(response.contentAsString, List) then: - results.id == ['test-1', 'test-2', 'test-3', 'test-4'] + results.id == ['test-1', 'test-2', 'test-3', 'test-4', 'test-5'] } void '/applications/{application}/pipelines/search should only return pipelines of given types'() { @@ -426,6 +429,9 @@ class TaskControllerSpec extends Specification { ], [pipelineConfigId: "1", id: "test-5", startTime: clock.instant().minus(daysOfExecutionHistory, DAYS).minus(2, HOURS).toEpochMilli(), trigger: new ArtifactoryTrigger("libs-demo-local") + ], + [pipelineConfigId: "1", id: "test-6", startTime: clock.instant().minus(daysOfExecutionHistory, DAYS).minus(2, HOURS).toEpochMilli(), + trigger: new NexusTrigger("libs-nexus-local") ] ] @@ -475,6 +481,9 @@ class TaskControllerSpec extends Specification { ], [pipelineConfigId: "1", id: "test-5", startTime: clock.instant().minus(daysOfExecutionHistory, DAYS).minus(2, HOURS).toEpochMilli(), trigger: new ArtifactoryTrigger("libs-demo-local"), eventId: wrongEventId + ], + [pipelineConfigId: "1", id: "test-6", startTime: clock.instant().minus(daysOfExecutionHistory, DAYS).minus(2, HOURS).toEpochMilli(), + trigger: new NexusTrigger("libs-nexus-local"), eventId: wrongEventId ] ]