From cdf1a97e68b4c3e679528e52ab634b68b3ae5d3b Mon Sep 17 00:00:00 2001 From: anotherchrisberry Date: Fri, 1 Dec 2017 14:01:54 -0800 Subject: [PATCH] chore(mahe): remove mahe --- orca-mahe/orca-mahe.gradle | 20 - .../spinnaker/orca/mahe/MaheService.groovy | 41 -- .../spinnaker/orca/mahe/PropertyAction.groovy | 42 -- .../FastPropertyCleanupListener.groovy | 158 ----- .../orca/mahe/config/MaheConfiguration.groovy | 81 --- .../mahe/pipeline/CreatePropertyStage.groovy | 48 -- .../MonitorCreatePropertyStage.groovy | 52 -- .../UpdatePersistedPropertyStage.groovy | 59 -- .../mahe/tasks/CreatePropertiesTask.groovy | 127 ---- .../orca/mahe/tasks/DeletePropertyTask.groovy | 62 -- .../mahe/tasks/MonitorPropertiesTask.groovy | 74 --- .../mahe/tasks/RollbackPropertyTask.groovy | 33 - .../tasks/CreatePropertiesTaskSpec.groovy | 380 ------------ .../tasks/DeletePropertiesTaskSpec.groovy | 92 --- .../tasks/MonitorPropertiesTaskSpec.groovy | 85 --- .../tasks/PropertyChangeCleanupSpec.groovy | 570 ------------------ orca-web/orca-web.gradle | 1 - .../com/netflix/spinnaker/orca/Main.groovy | 2 - settings.gradle | 1 - 19 files changed, 1928 deletions(-) delete mode 100644 orca-mahe/orca-mahe.gradle delete mode 100644 orca-mahe/src/main/groovy/com/netflix/spinnaker/orca/mahe/MaheService.groovy delete mode 100644 orca-mahe/src/main/groovy/com/netflix/spinnaker/orca/mahe/PropertyAction.groovy delete mode 100644 orca-mahe/src/main/groovy/com/netflix/spinnaker/orca/mahe/cleanup/FastPropertyCleanupListener.groovy delete mode 100644 orca-mahe/src/main/groovy/com/netflix/spinnaker/orca/mahe/config/MaheConfiguration.groovy delete mode 100644 orca-mahe/src/main/groovy/com/netflix/spinnaker/orca/mahe/pipeline/CreatePropertyStage.groovy delete mode 100644 orca-mahe/src/main/groovy/com/netflix/spinnaker/orca/mahe/pipeline/MonitorCreatePropertyStage.groovy delete mode 100644 orca-mahe/src/main/groovy/com/netflix/spinnaker/orca/mahe/pipeline/UpdatePersistedPropertyStage.groovy delete mode 100644 orca-mahe/src/main/groovy/com/netflix/spinnaker/orca/mahe/tasks/CreatePropertiesTask.groovy delete mode 100644 orca-mahe/src/main/groovy/com/netflix/spinnaker/orca/mahe/tasks/DeletePropertyTask.groovy delete mode 100644 orca-mahe/src/main/groovy/com/netflix/spinnaker/orca/mahe/tasks/MonitorPropertiesTask.groovy delete mode 100644 orca-mahe/src/main/groovy/com/netflix/spinnaker/orca/mahe/tasks/RollbackPropertyTask.groovy delete mode 100644 orca-mahe/src/test/groovy/com/netflix/spinnaker/orca/mahe/tasks/CreatePropertiesTaskSpec.groovy delete mode 100644 orca-mahe/src/test/groovy/com/netflix/spinnaker/orca/mahe/tasks/DeletePropertiesTaskSpec.groovy delete mode 100644 orca-mahe/src/test/groovy/com/netflix/spinnaker/orca/mahe/tasks/MonitorPropertiesTaskSpec.groovy delete mode 100644 orca-mahe/src/test/groovy/com/netflix/spinnaker/orca/mahe/tasks/PropertyChangeCleanupSpec.groovy diff --git a/orca-mahe/orca-mahe.gradle b/orca-mahe/orca-mahe.gradle deleted file mode 100644 index 6c2319c2e7..0000000000 --- a/orca-mahe/orca-mahe.gradle +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright 2016 Netflix, 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. - */ - -dependencies { - compile project(':orca-retrofit') - testCompile project(":orca-test") -} diff --git a/orca-mahe/src/main/groovy/com/netflix/spinnaker/orca/mahe/MaheService.groovy b/orca-mahe/src/main/groovy/com/netflix/spinnaker/orca/mahe/MaheService.groovy deleted file mode 100644 index e1169bb28e..0000000000 --- a/orca-mahe/src/main/groovy/com/netflix/spinnaker/orca/mahe/MaheService.groovy +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright 2016 Netflix, 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.mahe - -import retrofit.client.Response -import retrofit.http.* - -interface MaheService { - @POST('/properties/create') - Response createProperty(@Body Map property) - - @POST('/properties/upsert') - Response upsertProperty(@Body Map property) - - @GET('/properties/find') - Response findProperty(@QueryMap Map property) - - @GET('/properties/prop') - Response getPropertyById(@Query('propId') String propId, @Query('env') String env) - - @DELETE('/properties/delete') - Response deleteProperty( - @Query('propId') String propId, - @Query('cmcTicket') String cmcTicket, - @Query('env') String env - ) -} diff --git a/orca-mahe/src/main/groovy/com/netflix/spinnaker/orca/mahe/PropertyAction.groovy b/orca-mahe/src/main/groovy/com/netflix/spinnaker/orca/mahe/PropertyAction.groovy deleted file mode 100644 index d240642550..0000000000 --- a/orca-mahe/src/main/groovy/com/netflix/spinnaker/orca/mahe/PropertyAction.groovy +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright 2017 Netflix, 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.mahe - -import groovy.transform.CompileStatic - -/* - * Copyright 2017 Netflix, 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. - */ - -@CompileStatic -enum PropertyAction { - CREATE, - UPDATE, - DELETE, - UNKNOWN -} diff --git a/orca-mahe/src/main/groovy/com/netflix/spinnaker/orca/mahe/cleanup/FastPropertyCleanupListener.groovy b/orca-mahe/src/main/groovy/com/netflix/spinnaker/orca/mahe/cleanup/FastPropertyCleanupListener.groovy deleted file mode 100644 index 4877ac8a57..0000000000 --- a/orca-mahe/src/main/groovy/com/netflix/spinnaker/orca/mahe/cleanup/FastPropertyCleanupListener.groovy +++ /dev/null @@ -1,158 +0,0 @@ -/* - * Copyright 2016 Netflix, 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.mahe.cleanup - -import com.fasterxml.jackson.databind.ObjectMapper -import com.netflix.spinnaker.kork.core.RetrySupport -import com.netflix.spinnaker.orca.ExecutionStatus -import com.netflix.spinnaker.orca.listeners.ExecutionListener -import com.netflix.spinnaker.orca.listeners.Persister -import com.netflix.spinnaker.orca.mahe.MaheService -import com.netflix.spinnaker.orca.mahe.PropertyAction -import com.netflix.spinnaker.orca.pipeline.model.Execution -import com.netflix.spinnaker.orca.pipeline.model.Stage -import groovy.util.logging.Slf4j -import org.springframework.beans.factory.annotation.Autowired -import org.springframework.stereotype.Component -import retrofit.RetrofitError -import retrofit.client.Response - -@Slf4j -@Component -class FastPropertyCleanupListener implements ExecutionListener { - - private final MaheService mahe - - @Autowired - FastPropertyCleanupListener(MaheService mahe) { - this.mahe = mahe - } - - @Autowired ObjectMapper mapper - @Autowired RetrySupport retrySupport - - @Override - void afterExecution(Persister persister, - Execution execution, - ExecutionStatus executionStatus, - boolean wasSuccessful) { - - boolean rollbackBasedOnExecutionStatus = executionStatus in [ExecutionStatus.TERMINAL, ExecutionStatus.CANCELED] - List rollbacks = rollbackBasedOnExecutionStatus ? execution.stages : execution.stages.findAll { - it.context.rollbackProperties - } - - if (!rollbacks.empty) { - rollbacks.each { stage -> - switch (stage.outputs.propertyAction) { - case PropertyAction.CREATE.toString(): - stage.outputs.persistedProperties.each { Map prop -> - String propertyId = prop.propertyId - if (shouldRollback(prop)) { - log.info("Rolling back the creation of: ${propertyId} on execution ${execution.id} by deleting") - Response response = mahe.deleteProperty(propertyId, "spinnaker rollback", extractEnvironment(propertyId)) - resolveRollbackResponse(response, stage.outputs.propertyAction.toString(), prop) - } else { - log.info("Property ${propertyId} has been updated since this execution (${execution.id}); not rolling back create") - } - } - break - case PropertyAction.UPDATE.toString(): - stage.outputs.originalProperties.each { Map originalProp -> - Map property = originalProp.property ?: originalProp - Map updatedProperty = (Map) stage.outputs.persistedProperties.find { - it.propertyId == property.propertyId - } - String propertyId = property.propertyId - if (shouldRollback(updatedProperty)) { - log.info("Rolling back the update of: ${propertyId} on execution ${execution.id} by upserting") - Response response = mahe.upsertProperty(originalProp) - resolveRollbackResponse(response, stage.outputs.propertyAction.toString(), property) - } else { - log.info("Property ${propertyId} has been updated since this execution (${execution.id}); not rolling back update") - } - } - break - case PropertyAction.DELETE.toString(): - stage.outputs.originalProperties.each { Map originalProp -> - Map property = originalProp.property ?: originalProp - if (propertyExists(property)) { - log.info("Property ${property.propertyId} exists, not restoring to original state after delete.") - } else { - if (property.propertyId) { - property.remove('propertyId') - } - log.info("Rolling back the delete of: ${property.key}|${property.value} on execution ${execution.id} by re-creating") - - Response response = mahe.upsertProperty(originalProp) - resolveRollbackResponse(response, stage.outputs.propertyAction.toString(), property) - } - } - } - } - } - } - - private boolean shouldRollback(Map property) { - String propertyId = property.propertyId - String env = extractEnvironment(propertyId) - try { - return retrySupport.retry({ - Response propertyResponse = mahe.getPropertyById(propertyId, env) - Map currentProperty = mapper.readValue(propertyResponse.body.in().text, Map) - return currentProperty.property.ts == property.ts - }, 3, 2000, false) - } catch (RetrofitError error) { - if (error.response.status == 404) { - return false - } - throw error - } - } - - private boolean propertyExists(Map property) { - try { - return retrySupport.retry({ - mahe.getPropertyById(property.propertyId, property.env) - return true - }, 3, 2000, false) - } catch (RetrofitError error) { - if (error.kind == RetrofitError.Kind.HTTP && error.response.status == 404) { - return false - } - throw error - } - } - - private void resolveRollbackResponse(Response response, String initialPropertyAction, def property) { - if(response.status == 200) { - log.info("Successful Fast Property rollback for $initialPropertyAction") - if (response.body?.mimeType()?.startsWith('application/')) { - def json = mapper.readValue(response.body.in().text, Map) - log.info("Fast Property rollback response: $json") - } - } else { - throw new IllegalStateException("Unable to rollback ${initialPropertyAction} with $response for property $property") - } - } - - private String extractEnvironment(propertyId) { - propertyId.find(~/\w+\|\w+\|(\w+)\|.*?/) { match, env -> - env - } - } -} diff --git a/orca-mahe/src/main/groovy/com/netflix/spinnaker/orca/mahe/config/MaheConfiguration.groovy b/orca-mahe/src/main/groovy/com/netflix/spinnaker/orca/mahe/config/MaheConfiguration.groovy deleted file mode 100644 index a35cc0f0e7..0000000000 --- a/orca-mahe/src/main/groovy/com/netflix/spinnaker/orca/mahe/config/MaheConfiguration.groovy +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright 2016 Netflix, 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.mahe.config - -import com.fasterxml.jackson.databind.ObjectMapper -import com.netflix.spinnaker.orca.events.ExecutionEvent -import com.netflix.spinnaker.orca.events.ExecutionListenerAdapter -import com.netflix.spinnaker.orca.mahe.MaheService -import com.netflix.spinnaker.orca.mahe.cleanup.FastPropertyCleanupListener -import com.netflix.spinnaker.orca.pipeline.persistence.ExecutionRepository -import com.netflix.spinnaker.orca.retrofit.RetrofitConfiguration -import com.netflix.spinnaker.orca.retrofit.logging.RetrofitSlf4jLog -import org.springframework.beans.factory.annotation.Autowired -import org.springframework.beans.factory.annotation.Value -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty -import org.springframework.context.ApplicationListener -import org.springframework.context.annotation.Bean -import org.springframework.context.annotation.ComponentScan -import org.springframework.context.annotation.Configuration -import org.springframework.context.annotation.Import -import retrofit.Endpoint -import retrofit.RestAdapter -import retrofit.client.Client -import retrofit.converter.JacksonConverter -import static retrofit.Endpoints.newFixedEndpoint - -@Configuration -@Import([RetrofitConfiguration]) -@ComponentScan([ - "com.netflix.spinnaker.orca.mahe.pipeline", - "com.netflix.spinnaker.orca.mahe.tasks", - "com.netflix.spinnaker.orca.mahe.cleanup" -]) -@ConditionalOnProperty(value = 'mahe.baseUrl') -class MaheConfiguration { - - @Autowired - Client retrofitClient - - @Autowired - RestAdapter.LogLevel retrofitLogLevel - - @Autowired - ObjectMapper objectMapper - - @Bean - Endpoint maheEndpoint(@Value('${mahe.baseUrl}') String maheBaseUrl) { - newFixedEndpoint(maheBaseUrl) - } - - @Bean - MaheService maheService(Endpoint maheEndpoint) { - new RestAdapter.Builder() - .setEndpoint(maheEndpoint) - .setClient(retrofitClient) - .setLogLevel(retrofitLogLevel) - .setLog(new RetrofitSlf4jLog(MaheService)) - .setConverter(new JacksonConverter(objectMapper)) - .build() - .create(MaheService) - } - - @Bean - ApplicationListener fastPropertyCleanupListenerAdapter(FastPropertyCleanupListener fastPropertyCleanupListener, ExecutionRepository repository) { - new ExecutionListenerAdapter(fastPropertyCleanupListener, repository) - } -} diff --git a/orca-mahe/src/main/groovy/com/netflix/spinnaker/orca/mahe/pipeline/CreatePropertyStage.groovy b/orca-mahe/src/main/groovy/com/netflix/spinnaker/orca/mahe/pipeline/CreatePropertyStage.groovy deleted file mode 100644 index c256a85acb..0000000000 --- a/orca-mahe/src/main/groovy/com/netflix/spinnaker/orca/mahe/pipeline/CreatePropertyStage.groovy +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright 2016 Netflix, 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.mahe.pipeline - -import com.netflix.spinnaker.orca.CancellableStage -import com.netflix.spinnaker.orca.mahe.tasks.CreatePropertiesTask -import com.netflix.spinnaker.orca.mahe.tasks.MonitorPropertiesTask -import com.netflix.spinnaker.orca.pipeline.StageDefinitionBuilder -import com.netflix.spinnaker.orca.pipeline.TaskNode -import com.netflix.spinnaker.orca.pipeline.model.Stage -import groovy.util.logging.Slf4j -import org.springframework.beans.factory.annotation.Autowired -import org.springframework.stereotype.Component - -@Slf4j -@Component -class CreatePropertyStage implements StageDefinitionBuilder, CancellableStage { - public static final String PIPELINE_CONFIG_TYPE = getType(CreatePropertyStage) - - @Autowired MonitorCreatePropertyStage monitorCreatePropertyStage - - @Override - void taskGraph(Stage stage, TaskNode.Builder builder) { - builder - .withTask("createProperties", CreatePropertiesTask) - .withTask("monitorProperties", MonitorPropertiesTask) - } - - @Override - CancellableStage.Result cancel(Stage stage) { - return null - } -} - diff --git a/orca-mahe/src/main/groovy/com/netflix/spinnaker/orca/mahe/pipeline/MonitorCreatePropertyStage.groovy b/orca-mahe/src/main/groovy/com/netflix/spinnaker/orca/mahe/pipeline/MonitorCreatePropertyStage.groovy deleted file mode 100644 index b78bf442d6..0000000000 --- a/orca-mahe/src/main/groovy/com/netflix/spinnaker/orca/mahe/pipeline/MonitorCreatePropertyStage.groovy +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright 2016 Netflix, 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.mahe.pipeline - -import com.netflix.spinnaker.orca.CancellableStage -import com.netflix.spinnaker.orca.mahe.MaheService -import com.netflix.spinnaker.orca.mahe.tasks.CreatePropertiesTask -import com.netflix.spinnaker.orca.mahe.tasks.MonitorPropertiesTask -import com.netflix.spinnaker.orca.pipeline.StageDefinitionBuilder -import com.netflix.spinnaker.orca.pipeline.TaskNode -import com.netflix.spinnaker.orca.pipeline.model.Stage -import groovy.transform.CompileStatic -import groovy.util.logging.Slf4j -import org.springframework.beans.factory.annotation.Autowired -import org.springframework.stereotype.Component - -@Component -@CompileStatic -@Slf4j -class MonitorCreatePropertyStage implements StageDefinitionBuilder, CancellableStage { - public static - final String PIPELINE_CONFIG_TYPE = getType(MonitorCreatePropertyStage) - - @Autowired - MaheService maheService - - @Override - CancellableStage.Result cancel(Stage stage) { - return null - } - - @Override - void taskGraph(Stage stage, TaskNode.Builder builder) { - builder - .withTask("createProperties", CreatePropertiesTask) - .withTask("monitorProperties", MonitorPropertiesTask) - } -} diff --git a/orca-mahe/src/main/groovy/com/netflix/spinnaker/orca/mahe/pipeline/UpdatePersistedPropertyStage.groovy b/orca-mahe/src/main/groovy/com/netflix/spinnaker/orca/mahe/pipeline/UpdatePersistedPropertyStage.groovy deleted file mode 100644 index 3f81eca526..0000000000 --- a/orca-mahe/src/main/groovy/com/netflix/spinnaker/orca/mahe/pipeline/UpdatePersistedPropertyStage.groovy +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright 2016 Netflix, 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.mahe.pipeline - -import com.netflix.spinnaker.orca.CancellableStage -import com.netflix.spinnaker.orca.mahe.tasks.RollbackPropertyTask -import com.netflix.spinnaker.orca.pipeline.StageDefinitionBuilder -import com.netflix.spinnaker.orca.pipeline.model.Stage -import com.netflix.spinnaker.orca.pipeline.model.SyntheticStageOwner -import groovy.util.logging.Slf4j -import org.springframework.beans.factory.annotation.Autowired -import org.springframework.stereotype.Component - -@Slf4j -@Component -class UpdatePersistedPropertyStage implements StageDefinitionBuilder, CancellableStage { - @Autowired MonitorCreatePropertyStage monitorCreatePropertyStage - @Autowired RollbackPropertyTask rollbackPropertyTask - - @Override - def List aroundStages(Stage parentStage) { - return [ - newStage( - parentStage.execution, - monitorCreatePropertyStage.getType(), - "Monitor Update Property", - parentStage.context + [propertyStageId: parentStage.id], - parentStage, - SyntheticStageOwner.STAGE_AFTER - ) - ] - } - - @Override - CancellableStage.Result cancel(Stage stage) { - log.info("Cancelling stage (stageId: ${stage.id}, executionId: ${stage.execution.id}, context: ${stage.context as Map})") - - def deletedProperties = rollbackPropertyTask.execute(stage) - - return new CancellableStage.Result(stage, [ - deletedPropertyIdList: stage.context.propertyIdList, - deletedPropertiesResults: deletedProperties - ]) - } -} diff --git a/orca-mahe/src/main/groovy/com/netflix/spinnaker/orca/mahe/tasks/CreatePropertiesTask.groovy b/orca-mahe/src/main/groovy/com/netflix/spinnaker/orca/mahe/tasks/CreatePropertiesTask.groovy deleted file mode 100644 index 21758eaee6..0000000000 --- a/orca-mahe/src/main/groovy/com/netflix/spinnaker/orca/mahe/tasks/CreatePropertiesTask.groovy +++ /dev/null @@ -1,127 +0,0 @@ -/* - * Copyright 2016 Netflix, 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.mahe.tasks - -import com.fasterxml.jackson.databind.ObjectMapper -import com.netflix.spinnaker.orca.Task -import com.netflix.spinnaker.orca.TaskResult -import com.netflix.spinnaker.orca.mahe.MaheService -import com.netflix.spinnaker.orca.mahe.PropertyAction -import com.netflix.spinnaker.orca.pipeline.model.Stage -import com.netflix.spinnaker.orca.pipeline.util.ContextParameterProcessor -import groovy.util.logging.Slf4j -import org.springframework.beans.factory.annotation.Autowired -import org.springframework.stereotype.Component -import retrofit.RetrofitError -import retrofit.client.Response -import static com.netflix.spinnaker.orca.ExecutionStatus.SUCCEEDED -import static com.netflix.spinnaker.orca.pipeline.model.Execution.ExecutionType.PIPELINE - -@Slf4j -@Component -class CreatePropertiesTask implements Task { - - @Autowired MaheService maheService - @Autowired ObjectMapper mapper - @Autowired ContextParameterProcessor contextParameterProcessor - - @Override - TaskResult execute(Stage stage) { - Map context = stage.context - if (stage.execution.type == PIPELINE) { - List overrides = stage.execution.trigger.stageOverrides ?: [] - context = overrides.find { it.refId == stage.refId } ?: context - context = contextParameterProcessor.process(context, [execution: stage.execution], true) - } - List properties = assemblePersistedPropertyListFromContext(context, context.persistedProperties) - // originalProperties field is only present on ad-hoc property pipelines - not as part of a createProperty stage, - // so we'll need to add the original property if found - boolean hasOriginalProperties = context.originalProperties - List originalProperties = assemblePersistedPropertyListFromContext(context, context.originalProperties ?: []) - List propertyIdList = [] - PropertyAction propertyAction = PropertyAction.UNKNOWN - - properties.forEach { Map prop -> - Response response - if (context.delete) { - log.info("Deleting Property: ${prop.property.propertyId} on execution ${stage.execution.id}") - response = maheService.deleteProperty(prop.property.propertyId, 'delete', prop.property.env) - propertyAction = PropertyAction.DELETE - } else { - log.info("Upserting Property: ${prop} on execution ${stage.execution.id}") - Map existingProperty = getExistingProperty(prop.property) - log.info("Property ${prop.key} ${existingProperty ? 'exists' : 'does not exist'}") - response = maheService.upsertProperty(prop) - propertyAction = existingProperty ? PropertyAction.UPDATE : PropertyAction.CREATE - if (existingProperty && !hasOriginalProperties) { - originalProperties << existingProperty - } - } - - if (response.status == 200) { - if (response.body?.mimeType()?.startsWith('application/')) { - propertyIdList << mapper.readValue(response.body.in().text, Map) - } - } else { - throw new IllegalStateException("Unable to handle $response for property $prop") - } - } - - def contextUpdates = [ - propertyIdList : propertyIdList, - rollbackProperties: context.rollbackProperties as boolean - ] - def outputs = [ - originalProperties: originalProperties, - propertyAction: propertyAction, - ] - - return new TaskResult(SUCCEEDED, contextUpdates, outputs) - - } - - private Map getExistingProperty(Map prop) { - try { - Map propertyToFind = prop.findAll { it.key != 'value' } - return mapper.readValue(maheService.findProperty(propertyToFind).body.in().text, Map) - } catch (RetrofitError error) { - if (error.kind == RetrofitError.Kind.HTTP && error.response.status == 404) { - return null - } - throw error - } - } - - - List assemblePersistedPropertyListFromContext(Map context, List propertyList) { - Map scope = context.scope - scope.appId = scope.appIdList?.join(',') - String email = context.email - String cmcTicket = context.cmcTicket - - return propertyList.collect { Map prop -> - if(prop) { - prop << scope - prop.email = email - prop.sourceOfUpdate = 'spinnaker' - prop.cmcTicket = cmcTicket - [property: prop] - } - } - } - -} diff --git a/orca-mahe/src/main/groovy/com/netflix/spinnaker/orca/mahe/tasks/DeletePropertyTask.groovy b/orca-mahe/src/main/groovy/com/netflix/spinnaker/orca/mahe/tasks/DeletePropertyTask.groovy deleted file mode 100644 index 6b44d3d8bf..0000000000 --- a/orca-mahe/src/main/groovy/com/netflix/spinnaker/orca/mahe/tasks/DeletePropertyTask.groovy +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright 2016 Netflix, 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.mahe.tasks - -import com.netflix.spinnaker.orca.ExecutionStatus -import com.netflix.spinnaker.orca.Task -import com.netflix.spinnaker.orca.TaskResult -import com.netflix.spinnaker.orca.mahe.MaheService -import com.netflix.spinnaker.orca.pipeline.model.Stage -import groovy.util.logging.Slf4j -import org.springframework.beans.factory.annotation.Autowired -import org.springframework.stereotype.Component -import retrofit.client.Response - -@Slf4j -@Component -class DeletePropertyTask implements Task{ - - @Autowired MaheService maheService - - @Override - TaskResult execute(Stage stage) { - - List propertyIdList = stage.context.propertyIdList - Map scope = stage.context.scope - String env = scope.env - String cmcTicket = stage.context.cmcTicket - - List deletedPropertyIdList = [] - - propertyIdList.each { String propertyId -> - Response response = maheService.deleteProperty(propertyId, cmcTicket, env) - if (response.status == 200 && response.body.mimeType().startsWith('text/plain')) { - String deletedPropetyId = response.body.in().text - deletedPropertyIdList << deletedPropetyId - } else { - throw new IllegalStateException("Unable to handle $response for property $prop") - } - } - - def outputs = [ - deletedPropertyIdList: deletedPropertyIdList - ] - - return new TaskResult(ExecutionStatus.SUCCEEDED, outputs) - - } -} diff --git a/orca-mahe/src/main/groovy/com/netflix/spinnaker/orca/mahe/tasks/MonitorPropertiesTask.groovy b/orca-mahe/src/main/groovy/com/netflix/spinnaker/orca/mahe/tasks/MonitorPropertiesTask.groovy deleted file mode 100644 index 26e168637f..0000000000 --- a/orca-mahe/src/main/groovy/com/netflix/spinnaker/orca/mahe/tasks/MonitorPropertiesTask.groovy +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright 2016 Netflix, 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.mahe.tasks - -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.mahe.MaheService -import com.netflix.spinnaker.orca.pipeline.model.Stage -import groovy.util.logging.Slf4j -import org.apache.http.HttpStatus -import org.springframework.beans.factory.annotation.Autowired -import org.springframework.stereotype.Component -import retrofit.RetrofitError -import retrofit.client.Response - -@Slf4j -@Component -class MonitorPropertiesTask implements Task { - @Autowired MaheService maheService - @Autowired ObjectMapper mapper - - @Override - TaskResult execute(Stage stage) { - - Map context = stage.context - log.info("MonitorPropertiesTask context: $context") - List propertyIds = context.propertyIdList*.propertyId - log.info("propertyIds: $propertyIds") - - List fetchedProperties = [] - - Map outputs = [ - persistedProperties: fetchedProperties - ] - - propertyIds.forEach { String id -> - try { - Response response = maheService.getPropertyById(id, context.scope.env) - if (response.status == HttpStatus.SC_OK) { - Map responseMap = mapper.readValue(response.body.in().text, Map) - fetchedProperties << responseMap.property - } - - } catch (RetrofitError e) { - log.error("Exception occurred while getting persisted property with id ${id} from mahe service", e) - return new TaskResult(ExecutionStatus.RUNNING, [:], outputs) - } - } - - - if (outputs.persistedProperties.size() == propertyIds.size()) { - return new TaskResult(ExecutionStatus.SUCCEEDED, [:], outputs) - } - - log.info("create persited properties in progress: ${outputs}") - return new TaskResult(ExecutionStatus.RUNNING, [:], outputs) - } -} diff --git a/orca-mahe/src/main/groovy/com/netflix/spinnaker/orca/mahe/tasks/RollbackPropertyTask.groovy b/orca-mahe/src/main/groovy/com/netflix/spinnaker/orca/mahe/tasks/RollbackPropertyTask.groovy deleted file mode 100644 index 241d1263d0..0000000000 --- a/orca-mahe/src/main/groovy/com/netflix/spinnaker/orca/mahe/tasks/RollbackPropertyTask.groovy +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright 2016 Netflix, 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.mahe.tasks - -import groovy.util.logging.Slf4j -import com.netflix.spinnaker.orca.Task -import com.netflix.spinnaker.orca.TaskResult -import com.netflix.spinnaker.orca.pipeline.model.Stage -import org.springframework.stereotype.Component - -@Slf4j -@Component -class RollbackPropertyTask implements Task{ - - @Override - TaskResult execute(Stage stage) { - return null - } -} diff --git a/orca-mahe/src/test/groovy/com/netflix/spinnaker/orca/mahe/tasks/CreatePropertiesTaskSpec.groovy b/orca-mahe/src/test/groovy/com/netflix/spinnaker/orca/mahe/tasks/CreatePropertiesTaskSpec.groovy deleted file mode 100644 index 8b398f0fe6..0000000000 --- a/orca-mahe/src/test/groovy/com/netflix/spinnaker/orca/mahe/tasks/CreatePropertiesTaskSpec.groovy +++ /dev/null @@ -1,380 +0,0 @@ -/* - * Copyright 2016 Netflix, 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.mahe.tasks - -import com.fasterxml.jackson.databind.ObjectMapper -import com.netflix.spinnaker.orca.mahe.MaheService -import com.netflix.spinnaker.orca.mahe.pipeline.CreatePropertyStage -import com.netflix.spinnaker.orca.mahe.pipeline.MonitorCreatePropertyStage -import com.netflix.spinnaker.orca.pipeline.model.Execution -import com.netflix.spinnaker.orca.pipeline.model.PipelineBuilder -import com.netflix.spinnaker.orca.pipeline.model.Stage -import com.netflix.spinnaker.orca.pipeline.util.ContextParameterProcessor -import retrofit.RetrofitError -import retrofit.client.Response -import retrofit.mime.TypedByteArray -import retrofit.mime.TypedString -import spock.lang.Specification -import spock.lang.Unroll - -class CreatePropertiesTaskSpec extends Specification { - - MaheService maheService = Mock(MaheService) - ObjectMapper mapper = new ObjectMapper() - - CreatePropertiesTask task = new CreatePropertiesTask(maheService: maheService, mapper: mapper, contextParameterProcessor: new ContextParameterProcessor()) - - RetrofitError NOT_FOUND = new RetrofitError(null, null, new Response("http://clouddriver", 404, "null", [], null), null, null, RetrofitError.Kind.HTTP, null) - - def "assemble the changed property list and original from the context"() { - given: - def pipeline = Execution.newPipeline('foo') - def scope = createScope() - def property = createProperty() - def originalProperty = createProperty() - - def stage = createPropertiesStage(pipeline, scope, property, originalProperty) - - when: - List properties = task.assemblePersistedPropertyListFromContext(stage.context, stage.context.persistedProperties) - List originalProperties = task.assemblePersistedPropertyListFromContext(stage.context, stage.context.originalProperties) - - then: "this is what the property payload that is sent to MAHE needs to look like" - properties.size() == 1 - originalProperties.size() == 1 - - [properties, originalProperties].forEach { prop -> - with(prop.first().property) { - key == property.key - value == property.value - email == 'test@netflix.com' - sourceOfUpdate == 'spinnaker' - constraints == property.constraints - cmcTicket == 'cmcTicket' - description == property.description - env == scope.env - region == scope.region - stack == scope.stack - cluster == scope.cluster - appId == scope.appIdList.first() - } - } - } - - def "adds original property to outputs if none present in stage context"() { - given: - def pipeline = Execution.newPipeline('foo') - def scope = createScope() - def property = createProperty() - def originalProperty = createProperty() - - def stage = createPropertiesStage(pipeline, scope, property, originalProperty) - stage.context.remove("originalProperties") - - when: - def results = task.execute(stage) - - then: - 1 * maheService.findProperty(_) >> new Response('', 200, 'OK', [], new TypedString(mapper.writeValueAsString([a: 1]))) - 1 * maheService.upsertProperty(_) >> { Map res -> - def json = mapper.writeValueAsString([propertyId: 'propertyId']) - new Response("http://mahe", 200, "OK", [], new TypedByteArray('application/json', json.bytes)) - } - - then: - with(results.outputs) { - originalProperties.size() == 1 - originalProperties[0].a == 1 - } - } - - def "prefer a stage override if present for context"() { - given: - def trigger = [stageOverrides: []] - def pipeline = new PipelineBuilder("foo").withTrigger(trigger).build() - def stageOverride = createPropertiesStage(pipeline, createScope(), createProperty("other"), null) - stageOverride.context.refId = "a" - def property = createProperty() - def createPropertiesStage = createPropertiesStage(pipeline, createScope(), property, null) - createPropertiesStage.refId = "a" - pipeline.stages.addAll([createPropertiesStage, createMonitorStage(pipeline)]) - - pipeline.trigger.stageOverrides << stageOverride.context - - when: - def results = task.execute(createPropertiesStage) - - then: - 1 * maheService.findProperty(_) >> { throw NOT_FOUND } - 1 * maheService.upsertProperty(_) >> { Map res -> - def json = mapper.writeValueAsString([propertyId: 'other']) - new Response("http://mahe", 200, "OK", [], new TypedByteArray('application/json', json.bytes)) - } - - then: - - with(results.context) { - propertyIdList.size() == 1 - propertyIdList.contains(propertyId: 'other') - } - } - - def "should handle expressions in stage override"() { - given: "an override property containing an expression" - def trigger = [stageOverrides: []] - def pipeline = new PipelineBuilder("foo").withTrigger(trigger).build() - def stageOverride = createPropertiesStage( - pipeline, - createScope(), - createProperty([key: "foo", value: '${"hello world".split(" ") }'], "other"), - null - ) - - stageOverride.context.refId = "a" - def property = createProperty() - def createPropertiesStage = createPropertiesStage(pipeline, createScope(), property, null) - createPropertiesStage.refId = "a" - pipeline.stages.addAll([createPropertiesStage, createMonitorStage(pipeline)]) - - and: - pipeline.trigger.stageOverrides << stageOverride.context - - when: - def results = task.execute(createPropertiesStage) - - then: "the expression value should be evaluated " - 1 * maheService.findProperty(_) >> { throw NOT_FOUND } - 1 * maheService.upsertProperty(_) >> { Map res -> - assert res.property.key == "foo" - assert res.property.value[0] == "hello" - assert res.property.value[1] == "world" - def json = mapper.writeValueAsString([propertyId: 'other']) - new Response("http://mahe", 200, "OK", [], new TypedByteArray('application/json', json.bytes)) - } - - then: - - with(results.context) { - propertyIdList.size() == 1 - propertyIdList.contains(propertyId: 'other') - } - } - - @Unroll("appIdList to appId: #appIdList -> #expectedAppId") - def "assemblePersistedPropertyListFromContext with one application in scope list"() { - given: - def pipeline = Execution.newPipeline('foo') - def scope = createScope() - def property = createProperty() - scope.appIdList = appIdList - - def stage = createPropertiesStage(pipeline, scope, property, []) - - when: - List properties = task.assemblePersistedPropertyListFromContext(stage.context, stage.context.persistedProperties) - - then: - properties.size() == 1 - properties[0].property.appId == expectedAppId - - where: - - appIdList | expectedAppId - [] | "" - ["deck"] | "deck" - ["deck", "mahe"] | "deck,mahe" - ["deck", "mahe", "orca"] | "deck,mahe,orca" - } - - def "assemble the changed property list if list is null for a new property"() { - given: - def pipeline = Execution.newPipeline('foo') - def scope = createScope() - def property = createProperty() - def originalProperty = [] - - def stage = createPropertiesStage(pipeline, scope, property, originalProperty) - - when: - List properties = task.assemblePersistedPropertyListFromContext(stage.context, stage.context.persistedProperties) - List originalProperties = task.assemblePersistedPropertyListFromContext(stage.context, stage.context.originalProperties) - - then: "this is what the property payload the is sent to MAHE needs to look like" - properties.size() == 1 - originalProperties.size() == 0 - } - - def "create a single new persistent property"() { - given: - def pipeline = Execution.newPipeline('foo') - def property = createProperty() - def createPropertiesStage = createPropertiesStage(pipeline, createScope(), property, null) - pipeline.stages.addAll([createPropertiesStage, createMonitorStage(pipeline)]) - - - when: - def results = task.execute(createPropertiesStage) - - then: - 1 * maheService.findProperty(_) >> { throw NOT_FOUND } - 1 * maheService.upsertProperty(_) >> { Map res -> - def json = mapper.writeValueAsString([propertyId: 'propertyId']) - new Response("http://mahe", 200, "OK", [], new TypedByteArray('application/json', json.bytes)) - } - - then: - - with(results.context) { - propertyIdList.size() == 1 - propertyIdList.contains(propertyId: 'propertyId') - } - } - - def "successfully delete single persisted properties"() { - given: - def pipeline = Execution.newPipeline('foo') - def scope = createScope() - def propertyId = '123propertyId' - def property = createProperty(propertyId) - def propertiesStage = createPropertiesStage(pipeline, scope, property, null) - propertiesStage.context["delete"] = true - pipeline.stages.addAll([propertiesStage, createMonitorStage(pipeline)]) - - when: - def results = task.execute(propertiesStage) - - then: - 1 * maheService.deleteProperty(property.propertyId, 'delete', scope.env) >> { - def res -> - def json = mapper.writeValueAsString([propertyId: 'propertyId']) - new Response("http://mahe", 200, "OK", [], null) - } - - then: "deleting a fast property does not return a property ID" - with(results.context) { - propertyIdList.size() == 0 - } - } - - def "delete a persisted properties that doen't exist"() { - given: - def pipeline = Execution.newPipeline('foo') - def scope = createScope() - def propertyId = 'invalid_id' - def property = createProperty(propertyId) - def propertiesStage = createPropertiesStage(pipeline, scope, property, null) - propertiesStage.context["delete"] = true - pipeline.stages.addAll([propertiesStage, createMonitorStage(pipeline)]) - - when: - def results = task.execute(propertiesStage) - - then: - 1 * maheService.deleteProperty(property.propertyId, 'delete', scope.env) >> { - def res -> - def json = mapper.writeValueAsString([error: "com.netflix.fastproperty.api.model.PropertyNotFound : property null"]) - new Response("http://mahe", 400, "OK", [], new TypedByteArray('application/json', json.bytes)) - } - - then: - thrown(IllegalStateException) - - } - - def "create multiple new persistent properties"() { - given: - def pipeline = Execution.newPipeline('foo') - def parentStageId = UUID.randomUUID().toString() - - - def properties = [ - [key: "foo", value: 'bar'], - [key: "foo1", value: 'baz'] - ] - - def createPropertiesStage = new Stage(pipeline, CreatePropertyStage.PIPELINE_CONFIG_TYPE, [ - scope : createScope(), - persistedProperties: properties, - email : 'foo@netflix.com', - cmcTicket : 'newCMCTiix' - ]) - - createPropertiesStage.parentStageId = parentStageId - def monitorCreatePropertyStage = new Stage(pipeline, MonitorCreatePropertyStage.PIPELINE_CONFIG_TYPE) - - pipeline.stages.addAll([createPropertiesStage, monitorCreatePropertyStage]) - - Map captured - - when: - def results = task.execute(createPropertiesStage) - - then: - - 2 * maheService.findProperty(_) >> { throw NOT_FOUND } - 2 * maheService.upsertProperty(_) >> { Map res -> - captured = res - String propId = "${res.property.key}|${res.property.value}" - def json = mapper.writeValueAsString([propertyId: propId]) - new Response("http://mahe", 200, "OK", [], new TypedByteArray('application/json', json.bytes)) - } - - then: - with(results.context) { - propertyIdList.size() == 2 - propertyIdList.contains(propertyId: "${properties[0].key}|${properties[0].value}".toString()) - propertyIdList.contains(propertyId: "${properties[1].key}|${properties[1].value}".toString()) - } - } - - def createPropertiesStage(pipeline, scope, property, originalProperty) { - def context = [ - parentStageId : UUID.randomUUID().toString(), - scope : scope, - persistedProperties: [property], - originalProperties : originalProperty ? [originalProperty] : null, - email : 'test@netflix.com', - cmcTicket : 'cmcTicket' - ] - new Stage(pipeline, CreatePropertyStage.PIPELINE_CONFIG_TYPE, context) - } - - def createMonitorStage(pipeline) { - new Stage(pipeline, MonitorCreatePropertyStage.PIPELINE_CONFIG_TYPE) - } - - def createScope() { - [ - env : "test", - appIdList: ["foo"], - region : "us-west-1", - stack : "main", - cluster : "foo-main", - ] - } - - def createProperty(propertyId = null) { - def property = [key: "foo", value: 'bar', constraints: 'none'] - property['propertyId'] = propertyId - property - } - - def createProperty(Map property, propertyId = null) { - property['propertyId'] = propertyId - property - } -} diff --git a/orca-mahe/src/test/groovy/com/netflix/spinnaker/orca/mahe/tasks/DeletePropertiesTaskSpec.groovy b/orca-mahe/src/test/groovy/com/netflix/spinnaker/orca/mahe/tasks/DeletePropertiesTaskSpec.groovy deleted file mode 100644 index 9ef3f1eee3..0000000000 --- a/orca-mahe/src/test/groovy/com/netflix/spinnaker/orca/mahe/tasks/DeletePropertiesTaskSpec.groovy +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Copyright 2016 Netflix, 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.mahe.tasks - -import com.netflix.spinnaker.orca.mahe.MaheService -import com.netflix.spinnaker.orca.mahe.pipeline.CreatePropertyStage -import com.netflix.spinnaker.orca.pipeline.model.Execution -import com.netflix.spinnaker.orca.pipeline.model.Stage -import retrofit.client.Response -import retrofit.mime.TypedString -import spock.lang.IgnoreRest -import spock.lang.Specification - -/* - * Copyright 2016 Netflix, 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. - */ - -class DeletePropertiesTaskSpec extends Specification { - - MaheService maheService = Mock(MaheService) - - DeletePropertyTask task = new DeletePropertyTask(maheService: maheService) - - @IgnoreRest - def "delete a single new persistent property"() { - given: - def pipeline = Execution.newPipeline('foo') - def scope = [ - env: "test", - appIdList: ["foo"], - region: "us-west-1", - stack: "main", - cluster: "foo-main", - ] - - def property = [key:"foo", value:'bar', constraints: 'none'] - - def propertyIdList = ['foo|bar'] - - def createPropertiesStage = new Stage(pipeline, CreatePropertyStage.PIPELINE_CONFIG_TYPE, [ - scope: scope, - persistedProperties:[ property ], - email: 'zthrash@netflix.com', - cmcTicket: 'cmcTicket', - propertyIdList: propertyIdList - ]) - - List captured - - when: - def results = task.execute(createPropertiesStage) - - then: - 1 * maheService.deleteProperty(propertyIdList.first(), 'cmcTicket', scope.env) >> { res -> - captured = res - new Response("http://mahe", 200, "OK", [], new TypedString(propertyIdList.first())) - } - - then: - with(results.context) { - deletedPropertyIdList.size() == 1 - deletedPropertyIdList.contains(propertyIdList.first()) - } - } - -} diff --git a/orca-mahe/src/test/groovy/com/netflix/spinnaker/orca/mahe/tasks/MonitorPropertiesTaskSpec.groovy b/orca-mahe/src/test/groovy/com/netflix/spinnaker/orca/mahe/tasks/MonitorPropertiesTaskSpec.groovy deleted file mode 100644 index 18e1aebd8d..0000000000 --- a/orca-mahe/src/test/groovy/com/netflix/spinnaker/orca/mahe/tasks/MonitorPropertiesTaskSpec.groovy +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright 2016 Netflix, 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.mahe.tasks - -import com.fasterxml.jackson.databind.ObjectMapper -import com.netflix.spinnaker.orca.TaskResult -import com.netflix.spinnaker.orca.mahe.MaheService -import com.netflix.spinnaker.orca.mahe.pipeline.MonitorCreatePropertyStage -import com.netflix.spinnaker.orca.pipeline.model.Execution -import com.netflix.spinnaker.orca.pipeline.model.Stage -import groovy.json.JsonOutput -import retrofit.client.Response -import retrofit.mime.TypedByteArray -import spock.lang.Specification -import static com.netflix.spinnaker.orca.ExecutionStatus.SUCCEEDED - -/* - * Copyright 2016 Netflix, 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. - */ - -class MonitorPropertiesTaskSpec extends Specification { - - MaheService maheService = Mock(MaheService) - ObjectMapper mapper = new ObjectMapper() - MonitorPropertiesTask task = new MonitorPropertiesTask(maheService: maheService, mapper: mapper) - - def "monitor newly created persisted property still running"() { - given: - def pipeline = Execution.newPipeline('foo') - List propertyIds = [[propertyId: propId]] - List persistedProperty = [[key: 'foo', value:'bar']] - Map context = [propertyIdList: propertyIds, persistedProperties: persistedProperty, scope: scope] - def stage = new Stage(pipeline, MonitorCreatePropertyStage.PIPELINE_CONFIG_TYPE, context) - - when: - TaskResult result = task.execute(stage) - - then: - 1 * maheService.getPropertyById(propId, scope.env) >> { String id, String env -> - def body = JsonOutput.toJson([property: [propertyId: id, key: "foo", value: "bar"]]) - new Response("http://mahe", 200, "OK", [], new TypedByteArray('application/json', body.bytes)) - } - - then: - result.status == SUCCEEDED - result.outputs.persistedProperties.size() == 1 - - with(result.outputs.persistedProperties.first()) { - propertyId == propId - key == "foo" - value == "bar" - } - - where: - propId = "foo|bar" - scope = [env: "prod"] - } - -} diff --git a/orca-mahe/src/test/groovy/com/netflix/spinnaker/orca/mahe/tasks/PropertyChangeCleanupSpec.groovy b/orca-mahe/src/test/groovy/com/netflix/spinnaker/orca/mahe/tasks/PropertyChangeCleanupSpec.groovy deleted file mode 100644 index 73b5fdc2b2..0000000000 --- a/orca-mahe/src/test/groovy/com/netflix/spinnaker/orca/mahe/tasks/PropertyChangeCleanupSpec.groovy +++ /dev/null @@ -1,570 +0,0 @@ -/* - * Copyright 2016 Netflix, 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.mahe.tasks - -import com.fasterxml.jackson.databind.ObjectMapper -import com.netflix.spinnaker.kork.core.RetrySupport -import com.netflix.spinnaker.orca.ExecutionStatus -import com.netflix.spinnaker.orca.mahe.MaheService -import com.netflix.spinnaker.orca.mahe.PropertyAction -import com.netflix.spinnaker.orca.mahe.cleanup.FastPropertyCleanupListener -import com.netflix.spinnaker.orca.pipeline.persistence.ExecutionRepository -import retrofit.RetrofitError -import retrofit.client.Response -import retrofit.mime.TypedByteArray -import retrofit.mime.TypedString -import spock.lang.Specification -import spock.lang.Subject -import spock.lang.Unroll -import static com.netflix.spinnaker.orca.mahe.PropertyAction.* -import static com.netflix.spinnaker.orca.mahe.pipeline.CreatePropertyStage.PIPELINE_CONFIG_TYPE -import static com.netflix.spinnaker.orca.test.model.ExecutionBuilder.pipeline -import static com.netflix.spinnaker.orca.test.model.ExecutionBuilder.stage - -class PropertyChangeCleanupSpec extends Specification { - - ObjectMapper mapper = new ObjectMapper() - RetrySupport retrySupport = new NoSleepRetry() - def repository = Stub(ExecutionRepository) - def mahe = Mock(MaheService) - @Subject def listener = new FastPropertyCleanupListener(mahe) - - RetrofitError NOT_FOUND = new RetrofitError(null, null, new Response("http://clouddriver", 404, "null", [], null), null, null, RetrofitError.Kind.HTTP, null) - - def setup() { - listener.mapper = mapper - listener.retrySupport = retrySupport - } - - @Unroll() - def "a deleted property is restored to its original stage if the pipeline is #executionStatus and has matching original property"() { - given: - def pipeline = pipeline { - stage { - type = PIPELINE_CONFIG_TYPE - name = PIPELINE_CONFIG_TYPE - outputs = [ - propertyAction : DELETE.toString(), - originalProperties: [[property: originalProperty]] - ] - } - } - - repository.retrieve(pipeline.type, pipeline.id) >> pipeline - - when: - listener.afterExecution(null, pipeline, executionStatus, false) - - then: - 3 * mahe.getPropertyById(propertyId, _) >> { throw NOT_FOUND } - 1 * mahe.upsertProperty(_) >> { Map res -> - String propId = "${res.property.key}|${res.property.value}" - def json = mapper.writeValueAsString([propertyId: propId]) - new Response("http://mahe", 200, "OK", [], new TypedByteArray('application/json', json.bytes)) - } - - where: - propertyId = "test_rfletcher|mahe|test|us-west-1||||asg=mahe-test-v010|cluster=mahe-test" - propertyEnv = "test" - originalProperty = createPropertyWithId(propertyId) - executionStatus << [ExecutionStatus.TERMINAL, ExecutionStatus.CANCELED] - } - - def "failed upsert rollback should throw an IllegalStateException"() { - given: - def pipeline = pipeline { - stage { - type = PIPELINE_CONFIG_TYPE - name = PIPELINE_CONFIG_TYPE - outputs = [ - originalProperties: [[property: originalProperty]], - propertyAction : DELETE.toString() - ] - } - } - - repository.retrieve(pipeline.type, pipeline.id) >> pipeline - - when: - listener.afterExecution(null, pipeline, executionStatus, false) - - then: - 1 * mahe.upsertProperty(_) >> { Map res -> - new Response("http://mahe", 500, "OK", [], null) - } - - 3 * mahe.getPropertyById(propertyId, propertyEnv) >> { throw NOT_FOUND } - - IllegalStateException ex = thrown() - assert ex.message.contains("Unable to rollback DELETE") - - where: - propertyId = "test_rfletcher|mahe|test|us-west-1||||asg=mahe-test-v010|cluster=mahe-test" - propertyEnv = "test" - originalProperty = createPropertyWithId(propertyId) - executionStatus = ExecutionStatus.TERMINAL - } - - @Unroll() - def "a update property does not revert if original state is missing and the pipeline is #executionStatus"() { - given: - def pipeline = pipeline { - stage { - type = PIPELINE_CONFIG_TYPE - name = PIPELINE_CONFIG_TYPE - } - } - - repository.retrieve(pipeline.type, pipeline.id) >> pipeline - - when: - listener.afterExecution(null, pipeline, executionStatus, false) - - then: - 0 * mahe.upsertProperty(_) - 0 * mahe.deleteProperty(_, _, _) - - where: - propertyId = "test_rfletcher|mahe|test|us-west-1||||asg=mahe-test-v010|cluster=mahe-test" - propertyEnv = "test" - executionStatus << [ExecutionStatus.TERMINAL, ExecutionStatus.CANCELED] - } - - def "properties marked for rollback are rolled back on a successful execution"() { - given: - def pipeline = pipeline { - stage { - type = PIPELINE_CONFIG_TYPE - name = PIPELINE_CONFIG_TYPE - context = [ - rollbackProperties: true - ] - outputs = [ - persistedProperties: [[propertyId: createPropertyId]], - originalProperties : [], - propertyAction : CREATE.toString() - ] - } - stage { - type = PIPELINE_CONFIG_TYPE - name = PIPELINE_CONFIG_TYPE - context = [ - rollbackProperties: true - ] - outputs = [ - originalProperties: [[property: previous]], - propertyAction : DELETE.toString() - ] - } - stage { - type = PIPELINE_CONFIG_TYPE - name = PIPELINE_CONFIG_TYPE - outputs = [ - originalProperties: [[property: retainedPrevious]], - propertyAction : CREATE.toString() - ] - } - } - - when: - listener.afterExecution(null, pipeline, ExecutionStatus.SUCCEEDED, true) - - then: - - 1 * mahe.getPropertyById(createPropertyId, _) >> new Response('', 200, 'OK', [], new TypedString(mapper.writeValueAsString([property: [:]]))) - 3 * mahe.getPropertyById(deletePropertyId, _) >> { throw NOT_FOUND } - - 1 * mahe.deleteProperty(createPropertyId, 'spinnaker rollback', propertyEnv) >> { - def res -> - def json = mapper.writeValueAsString([propertyId: createPropertyId]) - new Response("http://mahe", 200, "OK", [], new TypedByteArray('application/json', json.bytes)) - } - - 1 * mahe.upsertProperty(_) >> { Map res -> - String propId = "${res.property.key}|${res.property.value}" - def json = mapper.writeValueAsString([propertyId: propId]) - new Response("http://mahe", 200, "OK", [], new TypedByteArray('application/json', json.bytes)) - } - 0 * _ - - where: - createPropertyId = "a|b|test|us-west-1||||asg=mahe-test-v010|cluster=mahe-test" - deletePropertyId = "a|b|test|us-west-1||||asg=mahe-test-v010|cluster=mahe-test" - retainPropertyId = "a|b|test|us-west-1||||asg=mahe-test-v010|cluster=mahe-test" - propertyEnv = "test" - previous = createPropertyWithId(deletePropertyId) - retainedPrevious = createPropertyWithId(retainPropertyId) - } - - @Unroll() - def "a newly created property should be deleted if the pipeline status is #executionStatus and has matching original property"() { - given: - def pipeline = pipeline { - stage { - type = PIPELINE_CONFIG_TYPE - name = PIPELINE_CONFIG_TYPE - outputs = [ - persistedProperties: [[propertyId: propertyId]], - originalProperties : [], - propertyAction : CREATE - ] - } - } - - repository.retrieve(pipeline.type, pipeline.id) >> pipeline - - when: - listener.afterExecution(null, pipeline, executionStatus, false) - - then: - 1 * mahe.getPropertyById(propertyId, _) >> new Response('', 200, 'OK', [], new TypedString(mapper.writeValueAsString([property: [:]]))) - 1 * mahe.deleteProperty(propertyId, 'spinnaker rollback', propertyEnv) >> { - def res -> - new Response("http://mahe", 200, "OK", [], null) - } - - where: - propertyId = "test_rfletcher|mahe|test|us-west-1||||asg=mahe-test-v010|cluster=mahe-test" - propertyEnv = "test" - originalProperty = createPropertyWithId(propertyId) - executionStatus << [ExecutionStatus.TERMINAL, ExecutionStatus.CANCELED] - } - - def "failed rollback of delete should throw IllegalStateException"() { - given: - def pipeline = pipeline { - stage { - type = PIPELINE_CONFIG_TYPE - name = PIPELINE_CONFIG_TYPE - outputs = [ - persistedProperties: [[propertyId: propertyId]], - originalProperties : [], - propertyAction : CREATE - ] - } - } - - repository.retrieve(pipeline.type, pipeline.id) >> pipeline - - when: - listener.afterExecution(null, pipeline, executionStatus, false) - - then: - 1 * mahe.getPropertyById(propertyId, _) >> new Response('', 200, 'OK', [], new TypedString(mapper.writeValueAsString([property: [:]]))) - 1 * mahe.deleteProperty(propertyId, 'spinnaker rollback', propertyEnv) >> { - def res -> - new Response("http://mahe", 500, "OK", [], null) - } - - IllegalStateException ex = thrown() - assert ex.message.contains("Unable to rollback CREATE") - assert ex.message.contains(propertyId) - - where: - propertyId = "test_rfletcher|mahe|test|us-west-1||||asg=mahe-test-v010|cluster=mahe-test" - propertyEnv = "test" - originalProperty = createPropertyWithId(propertyId) - executionStatus << [ExecutionStatus.TERMINAL, ExecutionStatus.CANCELED] - } - - def "a property created by a pipeline stage marked for 'rollback' is cleaned up at the end"() { - given: - def pipeline = pipeline { - stage { - type = PIPELINE_CONFIG_TYPE - name = PIPELINE_CONFIG_TYPE - context = [ - rollbackProperties: true - ] - outputs = [ - persistedProperties: [[propertyId: propertyId]], - originalProperties : [], - propertyAction : CREATE.toString() - ] - } - } - repository.retrieve(pipeline.type, pipeline.id) >> pipeline - - when: - listener.afterExecution(null, pipeline, null, true) - - then: - 1 * mahe.getPropertyById(propertyId, _) >> new Response('', 200, 'OK', [], new TypedString(mapper.writeValueAsString([property: [:]]))) - 1 * mahe.deleteProperty(propertyId, 'spinnaker rollback', propertyEnv) >> { - def res -> - def json = mapper.writeValueAsString([propertyId: propertyId]) - new Response("http://mahe", 200, "OK", [], new TypedByteArray('application/json', json.bytes)) - } - - where: - propertyId = "test_rfletcher|mahe|test|us-west-1||||asg=mahe-test-v010|cluster=mahe-test" - propertyEnv = "test" - } - - def "a property updated by a pipeline stage is cleaned up at the end when marked for rollback"() { - given: - def pipeline = pipeline { - stage { - type = PIPELINE_CONFIG_TYPE - name = PIPELINE_CONFIG_TYPE - context = [ - rollbackProperties: true - ] - outputs = [ - persistedProperties: [[propertyId: propertyId]], - originalProperties : [previous], - propertyAction : PropertyAction.UPDATE.toString() - ] - } - } - repository.retrieve(pipeline.type, pipeline.id) >> pipeline - - when: - listener.afterExecution(null, pipeline, null, true) - - then: - 1 * mahe.getPropertyById(propertyId, _) >> new Response('', 200, 'OK', [], new TypedString(mapper.writeValueAsString([property: [:]]))) - 1 * mahe.upsertProperty(previous) >> { Map res -> - String propId = "${res.property.key}|${res.property.value}" - def json = mapper.writeValueAsString([propertyId: propId]) - new Response("http://mahe", 200, "OK", [], new TypedByteArray('application/json', json.bytes)) - } - - where: - propertyId = "test_rfletcher|mahe|test|us-west-1||||asg=mahe-test-v010|cluster=mahe-test" - propertyEnv = "test" - previous = [property: createPropertyWithId(propertyId)] - } - - def "a property not marked for 'rollback' and is deleted by pipeline stage and is not reverted"() { - given: - def pipeline = pipeline { - stage { - type = PIPELINE_CONFIG_TYPE - name = PIPELINE_CONFIG_TYPE - } - } - repository.retrieve(pipeline.type, pipeline.id) >> pipeline - - when: - listener.afterExecution(null, pipeline, null, true) - - then: - 0 * mahe.upsertProperty([property: previous]) - 0 * mahe.deleteProperty(_, _, _) - - where: - propertyId = "test_rfletcher|mahe|test|us-west-1||||asg=mahe-test-v010|cluster=mahe-test" - propertyEnv = "test" - previous = createPropertyWithId(propertyId) - - } - - def "rollback a pipeline with multiple create stages"() { - given: - def pipeline = pipeline { - 3.times { - stage { - type = PIPELINE_CONFIG_TYPE - name = PIPELINE_CONFIG_TYPE - outputs = [ - persistedProperties: [[propertyId: propertyId]], - originalProperties : [], - propertyAction : CREATE.toString() - ] - } - } - } - - when: - listener.afterExecution(null, pipeline, ExecutionStatus.TERMINAL, true) - - then: - 3 * mahe.getPropertyById(propertyId, _) >> new Response('', 200, 'OK', [], new TypedString(mapper.writeValueAsString([property: [:]]))) - 3 * mahe.deleteProperty(propertyId, 'spinnaker rollback', propertyEnv) >> { - def res -> - def json = mapper.writeValueAsString([propertyId: propertyId]) - new Response("http://mahe", 200, "OK", [], new TypedByteArray('application/json', json.bytes)) - } - - where: - propertyId = "test_rfletcher|mahe|test|us-west-1||||asg=mahe-test-v010|cluster=mahe-test" - propertyEnv = "test" - previous = createPropertyWithId(propertyId) - - } - - def "rollback a pipeline with a create and a delete stages that are created for a scope update"() { - given: - def pipeline = pipeline { - stage { - type = PIPELINE_CONFIG_TYPE - name = PIPELINE_CONFIG_TYPE - outputs = [ - persistedProperties: [[propertyId: propertyId]], - originalProperties : [], - propertyAction : CREATE.toString() - ] - } - stage { - type = PIPELINE_CONFIG_TYPE - name = PIPELINE_CONFIG_TYPE - outputs = [ - originalProperties: [[property: previous]], - propertyAction : DELETE.toString() - ] - } - } - - when: - listener.afterExecution(null, pipeline, ExecutionStatus.TERMINAL, true) - - then: - 1 * mahe.getPropertyById(propertyId, _) >> new Response('', 200, 'OK', [], new TypedString(mapper.writeValueAsString([property: [:]]))) - 3 * mahe.getPropertyById(deletedPropertyId, _) >> { throw NOT_FOUND } - 1 * mahe.deleteProperty(propertyId, 'spinnaker rollback', propertyEnv) >> { - def res -> - def json = mapper.writeValueAsString([propertyId: propertyId]) - new Response("http://mahe", 200, "OK", [], new TypedByteArray('application/json', json.bytes)) - } - - 1 * mahe.upsertProperty(_) >> { Map res -> - String propId = "${res.property.key}|${res.property.value}" - def json = mapper.writeValueAsString([propertyId: propId]) - new Response("http://mahe", 200, "OK", [], new TypedByteArray('application/json', json.bytes)) - } - - where: - propertyId = "test_rfletcher|mahe|test|us-west-1||||asg=mahe-test-v010|cluster=mahe-test" - deletedPropertyId = "test_rfletcher|mahe|test|us-west-1||||asg=mahe-test-v010|cluster=mahe-test2" - propertyEnv = "test" - previous = createPropertyWithId(deletedPropertyId) - - } - - def "does not attempt to roll back deleted property if it exists"() { - def pipeline = pipeline { - stage { - type = PIPELINE_CONFIG_TYPE - name = PIPELINE_CONFIG_TYPE - context = [ - rollbackProperties: true - ] - outputs = [ - originalProperties: [[property: previous]], - propertyAction : DELETE.toString() - ] - } - } - - when: - listener.afterExecution(null, pipeline, ExecutionStatus.SUCCEEDED, true) - - then: - - 1 * mahe.getPropertyById(propertyId, _) >> new Response('', 200, 'OK', [], new TypedString(mapper.writeValueAsString([:]))) - 0 * _ - - where: - propertyId = "a|b|test|us-west-1||||asg=mahe-test-v010|cluster=mahe-test" - propertyEnv = "test" - previous = createPropertyWithId(propertyId) - } - - def "does not attempt to roll back created property if it has been updated since pipeline created it"() { - def pipeline = pipeline { - stage { - type = PIPELINE_CONFIG_TYPE - name = PIPELINE_CONFIG_TYPE - context = [ - rollbackProperties: true - ] - outputs = [ - persistedProperties: [previous], - originalProperties : [], - propertyAction : CREATE.toString() - ] - } - } - - when: - listener.afterExecution(null, pipeline, ExecutionStatus.SUCCEEDED, true) - - then: - - 1 * mahe.getPropertyById(propertyId, _) >> new Response('', 200, 'OK', [], new TypedString(mapper.writeValueAsString([property: [ts: "2018"]]))) - 0 * _ - - where: - propertyId = "a|b|test|us-west-1||||asg=mahe-test-v010|cluster=mahe-test" - propertyEnv = "test" - previous = createPropertyWithId(propertyId) - } - - def "does not attempt to roll back updated property if it has been updated since pipeline created it"() { - def pipeline = pipeline { - stage { - type = PIPELINE_CONFIG_TYPE - name = PIPELINE_CONFIG_TYPE - context = [ - rollbackProperties: true - ] - outputs = [ - persistedProperties: [previous], - originalProperties : [[property: previous]], - propertyAction : UPDATE.toString() - ] - } - } - - when: - listener.afterExecution(null, pipeline, ExecutionStatus.SUCCEEDED, true) - - then: - - 1 * mahe.getPropertyById(propertyId, _) >> new Response('', 200, 'OK', [], new TypedString(mapper.writeValueAsString([property: [ts: "2018"]]))) - 0 * _ - - where: - propertyId = "a|b|test|us-west-1||||asg=mahe-test-v010|cluster=mahe-test" - propertyEnv = "test" - previous = createPropertyWithId(propertyId) - } - - def createPropertyWithId(propertyId) { - [ - "propertyId" : propertyId, - "key" : "test_rfletcher", - "value" : "test4", - "env" : "test", - "appId" : "mahe", - "region" : "us-west-1", - "cluster" : "mahe-test", - "asg" : "mahe-test-v010", - "updatedBy" : "rfletcher", - "sourceOfUpdate" : "postman", - "cmcTicket" : "rfletcher", - "ttl" : 0, - "ts" : "2016-03-16T18:20:29.554Z[GMT]", - "createdAsCanary": false] - } - - static class NoSleepRetry extends RetrySupport { - void sleep(long time) {} - } - -} diff --git a/orca-web/orca-web.gradle b/orca-web/orca-web.gradle index 040eb4403c..32440ccd21 100644 --- a/orca-web/orca-web.gradle +++ b/orca-web/orca-web.gradle @@ -42,7 +42,6 @@ dependencies { compile project(":orca-echo") compile project(":orca-kayenta") compile project(":orca-mine") - compile project(":orca-mahe") compile project(":orca-igor") compile project(":orca-webhook") compile project(":orca-eureka") diff --git a/orca-web/src/main/groovy/com/netflix/spinnaker/orca/Main.groovy b/orca-web/src/main/groovy/com/netflix/spinnaker/orca/Main.groovy index 8f4d3f09a3..087662b3f4 100644 --- a/orca-web/src/main/groovy/com/netflix/spinnaker/orca/Main.groovy +++ b/orca-web/src/main/groovy/com/netflix/spinnaker/orca/Main.groovy @@ -30,7 +30,6 @@ import com.netflix.spinnaker.orca.flex.config.FlexConfiguration import com.netflix.spinnaker.orca.front50.config.Front50Configuration import com.netflix.spinnaker.orca.igor.config.IgorConfiguration import com.netflix.spinnaker.orca.kayenta.config.KayentaConfiguration -import com.netflix.spinnaker.orca.mahe.config.MaheConfiguration import com.netflix.spinnaker.orca.mine.config.MineConfiguration import com.netflix.spinnaker.orca.web.config.WebConfiguration import com.netflix.spinnaker.orca.webhook.config.WebhookConfiguration @@ -64,7 +63,6 @@ import org.springframework.scheduling.annotation.EnableAsync DiscoveryPollingConfiguration, TomcatConfiguration, MineConfiguration, - MaheConfiguration, ApplicationConfig, StackdriverConfig, PipelineTemplateConfiguration, diff --git a/settings.gradle b/settings.gradle index d660a91e5b..2710294045 100644 --- a/settings.gradle +++ b/settings.gradle @@ -26,7 +26,6 @@ include "orca-extensionpoint", "orca-clouddriver", "orca-kayenta", "orca-mine", - "orca-mahe", "orca-test", "orca-flex", "orca-webhook",