diff --git a/common/src/main/java/com/sequenceiq/cloudbreak/rotation/secret/SecretRotationProgressService.java b/common/src/main/java/com/sequenceiq/cloudbreak/rotation/secret/SecretRotationProgressService.java deleted file mode 100644 index 5b459ae94f6..00000000000 --- a/common/src/main/java/com/sequenceiq/cloudbreak/rotation/secret/SecretRotationProgressService.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.sequenceiq.cloudbreak.rotation.secret; - -import java.util.Optional; - -import com.sequenceiq.cloudbreak.rotation.secret.step.SecretRotationStep; - -public interface SecretRotationProgressService { - - boolean isFinished(E entity); - - void finished(E entity); - - Optional latestStep(String resourceCrn, SecretType secretType, SecretRotationStep step, RotationFlowExecutionType executionType); - - void deleteAll(String resourceCrn, SecretType secretType); - -} diff --git a/common/src/main/java/com/sequenceiq/cloudbreak/rotation/secret/SecretType.java b/common/src/main/java/com/sequenceiq/cloudbreak/rotation/secret/SecretType.java deleted file mode 100644 index 2f1e37b4100..00000000000 --- a/common/src/main/java/com/sequenceiq/cloudbreak/rotation/secret/SecretType.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.sequenceiq.cloudbreak.rotation.secret; - -import java.util.List; - -import com.sequenceiq.cloudbreak.rotation.secret.step.SecretRotationStep; - -public interface SecretType { - List getSteps(); -} diff --git a/common/src/main/java/com/sequenceiq/cloudbreak/rotation/secret/application/ApplicationSecretRotationInformation.java b/common/src/main/java/com/sequenceiq/cloudbreak/rotation/secret/application/ApplicationSecretRotationInformation.java deleted file mode 100644 index 943e05c562a..00000000000 --- a/common/src/main/java/com/sequenceiq/cloudbreak/rotation/secret/application/ApplicationSecretRotationInformation.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.sequenceiq.cloudbreak.rotation.secret.application; - -import com.sequenceiq.cloudbreak.rotation.secret.SecretType; - -public interface ApplicationSecretRotationInformation { - - Class supportedSecretType(); - -} diff --git a/common/src/main/java/com/sequenceiq/cloudbreak/rotation/secret/step/SecretRotationStep.java b/common/src/main/java/com/sequenceiq/cloudbreak/rotation/secret/step/SecretRotationStep.java deleted file mode 100644 index 6a70eb7ba82..00000000000 --- a/common/src/main/java/com/sequenceiq/cloudbreak/rotation/secret/step/SecretRotationStep.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.sequenceiq.cloudbreak.rotation.secret.step; - -public interface SecretRotationStep { - -} diff --git a/common/src/main/java/com/sequenceiq/cloudbreak/rotation/secret/usage/SecretRotationUsageProcessor.java b/common/src/main/java/com/sequenceiq/cloudbreak/rotation/secret/usage/SecretRotationUsageProcessor.java deleted file mode 100644 index bdc6c8f7398..00000000000 --- a/common/src/main/java/com/sequenceiq/cloudbreak/rotation/secret/usage/SecretRotationUsageProcessor.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.sequenceiq.cloudbreak.rotation.secret.usage; - -import com.sequenceiq.cloudbreak.rotation.secret.RotationFlowExecutionType; -import com.sequenceiq.cloudbreak.rotation.secret.SecretType; - -public interface SecretRotationUsageProcessor { - - void rotationStarted(SecretType secretType, String resourceCrn, RotationFlowExecutionType executionType); - - void rotationFinished(SecretType secretType, String resourceCrn, RotationFlowExecutionType executionType); - - void rotationFailed(SecretType secretType, String resourceCrn, String reason, RotationFlowExecutionType executionType); - - void rollbackStarted(SecretType secretType, String resourceCrn, RotationFlowExecutionType executionType); - - void rollbackFinished(SecretType secretType, String resourceCrn, RotationFlowExecutionType executionType); - - void rollbackFailed(SecretType secretType, String resourceCrn, String reason, RotationFlowExecutionType executionType); -} diff --git a/common/src/test/java/com/sequenceiq/cloudbreak/rotation/secret/TestSecretRotationStep.java b/common/src/test/java/com/sequenceiq/cloudbreak/rotation/secret/TestSecretRotationStep.java deleted file mode 100644 index 9762cf49cbb..00000000000 --- a/common/src/test/java/com/sequenceiq/cloudbreak/rotation/secret/TestSecretRotationStep.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.sequenceiq.cloudbreak.rotation.secret; - -import com.sequenceiq.cloudbreak.rotation.secret.step.SecretRotationStep; - -public enum TestSecretRotationStep implements SecretRotationStep { - STEP - -} diff --git a/common/src/test/java/com/sequenceiq/cloudbreak/rotation/secret/TestSecretType.java b/common/src/test/java/com/sequenceiq/cloudbreak/rotation/secret/TestSecretType.java deleted file mode 100644 index 740c972c3ec..00000000000 --- a/common/src/test/java/com/sequenceiq/cloudbreak/rotation/secret/TestSecretType.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.sequenceiq.cloudbreak.rotation.secret; - -import static com.sequenceiq.cloudbreak.rotation.secret.TestSecretRotationStep.STEP; - -import java.util.List; - -import com.sequenceiq.cloudbreak.rotation.secret.step.SecretRotationStep; - -public enum TestSecretType implements SecretType { - TEST, - TEST_2; - - @Override - public List getSteps() { - return List.of(STEP); - } -} diff --git a/core-api/build.gradle b/core-api/build.gradle index 4d28d8eb8a0..ff243857448 100644 --- a/core-api/build.gradle +++ b/core-api/build.gradle @@ -15,6 +15,7 @@ jar { } dependencies { + implementation project(':secret-rotation-api') implementation project(':authorization-common-api') api project(':cloud-api') api project(':auth-connector') diff --git a/core-api/src/main/java/com/sequenceiq/cloudbreak/api/endpoint/v4/rotation/requests/StackV4SecretRotationRequest.java b/core-api/src/main/java/com/sequenceiq/cloudbreak/api/endpoint/v4/rotation/requests/StackV4SecretRotationRequest.java index 3c131025777..4decfbf4232 100644 --- a/core-api/src/main/java/com/sequenceiq/cloudbreak/api/endpoint/v4/rotation/requests/StackV4SecretRotationRequest.java +++ b/core-api/src/main/java/com/sequenceiq/cloudbreak/api/endpoint/v4/rotation/requests/StackV4SecretRotationRequest.java @@ -4,7 +4,7 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.sequenceiq.cloudbreak.auth.crn.CrnResourceDescriptor; -import com.sequenceiq.cloudbreak.rotation.secret.RotationFlowExecutionType; +import com.sequenceiq.cloudbreak.rotation.RotationFlowExecutionType; import com.sequenceiq.cloudbreak.validation.ValidCrn; import io.swagger.annotations.ApiModel; diff --git a/core-api/src/main/java/com/sequenceiq/cloudbreak/rotation/CloudbreakSecretRotationStep.java b/core-api/src/main/java/com/sequenceiq/cloudbreak/rotation/CloudbreakSecretRotationStep.java index 5b3c4aa7cd9..2bf152f86b1 100644 --- a/core-api/src/main/java/com/sequenceiq/cloudbreak/rotation/CloudbreakSecretRotationStep.java +++ b/core-api/src/main/java/com/sequenceiq/cloudbreak/rotation/CloudbreakSecretRotationStep.java @@ -1,7 +1,5 @@ package com.sequenceiq.cloudbreak.rotation; -import com.sequenceiq.cloudbreak.rotation.secret.step.SecretRotationStep; - public enum CloudbreakSecretRotationStep implements SecretRotationStep { CM_USER, SALT_PILLAR, diff --git a/core-api/src/main/java/com/sequenceiq/cloudbreak/rotation/CloudbreakSecretType.java b/core-api/src/main/java/com/sequenceiq/cloudbreak/rotation/CloudbreakSecretType.java index 2451ccb7706..b2cd243774d 100644 --- a/core-api/src/main/java/com/sequenceiq/cloudbreak/rotation/CloudbreakSecretType.java +++ b/core-api/src/main/java/com/sequenceiq/cloudbreak/rotation/CloudbreakSecretType.java @@ -6,17 +6,14 @@ import static com.sequenceiq.cloudbreak.rotation.CloudbreakSecretRotationStep.SALT_PILLAR; import static com.sequenceiq.cloudbreak.rotation.CloudbreakSecretRotationStep.SALT_STATE_APPLY; import static com.sequenceiq.cloudbreak.rotation.CloudbreakSecretRotationStep.SALT_STATE_RUN; -import static com.sequenceiq.cloudbreak.rotation.secret.step.CommonSecretRotationStep.CUSTOM_JOB; -import static com.sequenceiq.cloudbreak.rotation.secret.step.CommonSecretRotationStep.REDBEAMS_ROTATE_POLLING; -import static com.sequenceiq.cloudbreak.rotation.secret.step.CommonSecretRotationStep.SERVICE_CONFIG; -import static com.sequenceiq.cloudbreak.rotation.secret.step.CommonSecretRotationStep.USER_DATA; -import static com.sequenceiq.cloudbreak.rotation.secret.step.CommonSecretRotationStep.VAULT; +import static com.sequenceiq.cloudbreak.rotation.CommonSecretRotationStep.CUSTOM_JOB; +import static com.sequenceiq.cloudbreak.rotation.CommonSecretRotationStep.REDBEAMS_ROTATE_POLLING; +import static com.sequenceiq.cloudbreak.rotation.CommonSecretRotationStep.SALTBOOT_CONFIG; +import static com.sequenceiq.cloudbreak.rotation.CommonSecretRotationStep.USER_DATA; +import static com.sequenceiq.cloudbreak.rotation.CommonSecretRotationStep.VAULT; import java.util.List; -import com.sequenceiq.cloudbreak.rotation.secret.SecretType; -import com.sequenceiq.cloudbreak.rotation.secret.step.SecretRotationStep; - public enum CloudbreakSecretType implements SecretType { CLUSTER_CB_CM_ADMIN_PASSWORD(List.of(VAULT, CM_USER, CLUSTER_PROXY)), CLUSTER_MGMT_CM_ADMIN_PASSWORD(List.of(VAULT, CM_USER, CLUSTER_PROXY)), @@ -25,7 +22,7 @@ public enum CloudbreakSecretType implements SecretType { CLUSTER_CM_DB_PASSWORD(List.of(VAULT, SALT_PILLAR, SALT_STATE_APPLY, CUSTOM_JOB)), USER_KEYPAIR(List.of(SALT_STATE_RUN, CUSTOM_JOB)), CLUSTER_CM_SERVICES_DB_PASSWORD(List.of(VAULT, SALT_PILLAR, SALT_STATE_APPLY, CM_SERVICE)), - SALT_BOOT_SECRETS(List.of(VAULT, CUSTOM_JOB, SERVICE_CONFIG, USER_DATA)); + SALT_BOOT_SECRETS(List.of(VAULT, CUSTOM_JOB, SALTBOOT_CONFIG, USER_DATA)); private final List steps; diff --git a/core-api/src/main/java/com/sequenceiq/distrox/api/v1/distrox/model/DistroXSecretRotationRequest.java b/core-api/src/main/java/com/sequenceiq/distrox/api/v1/distrox/model/DistroXSecretRotationRequest.java index 565f4dd4659..5d0187d4a6c 100644 --- a/core-api/src/main/java/com/sequenceiq/distrox/api/v1/distrox/model/DistroXSecretRotationRequest.java +++ b/core-api/src/main/java/com/sequenceiq/distrox/api/v1/distrox/model/DistroXSecretRotationRequest.java @@ -6,7 +6,7 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.sequenceiq.cloudbreak.auth.crn.CrnResourceDescriptor; -import com.sequenceiq.cloudbreak.rotation.secret.RotationFlowExecutionType; +import com.sequenceiq.cloudbreak.rotation.RotationFlowExecutionType; import com.sequenceiq.cloudbreak.validation.ValidCrn; import io.swagger.annotations.ApiModel; diff --git a/core/build.gradle b/core/build.gradle index 6f49f04ea5e..83b8cacc2ab 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -230,6 +230,8 @@ dependencies { because 'because there is no jar for 2.4.3 in maven central repo...' } + implementation project(':secret-rotation') + implementation project(':secret-rotation-api') implementation project(':core-api') implementation project(':core-model') implementation project(':orchestrator-api') diff --git a/core/src/main/java/com/sequenceiq/cloudbreak/core/flow2/externaldatabase/ExternalDatabaseService.java b/core/src/main/java/com/sequenceiq/cloudbreak/core/flow2/externaldatabase/ExternalDatabaseService.java index a8706a59062..3d3f4d05452 100644 --- a/core/src/main/java/com/sequenceiq/cloudbreak/core/flow2/externaldatabase/ExternalDatabaseService.java +++ b/core/src/main/java/com/sequenceiq/cloudbreak/core/flow2/externaldatabase/ExternalDatabaseService.java @@ -37,8 +37,8 @@ import com.sequenceiq.cloudbreak.domain.stack.Stack; import com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster; import com.sequenceiq.cloudbreak.repository.cluster.ClusterRepository; -import com.sequenceiq.cloudbreak.rotation.secret.RotationFlowExecutionType; -import com.sequenceiq.cloudbreak.rotation.secret.SecretRotationException; +import com.sequenceiq.cloudbreak.rotation.RotationFlowExecutionType; +import com.sequenceiq.cloudbreak.rotation.common.SecretRotationException; import com.sequenceiq.cloudbreak.service.externaldatabase.DatabaseOperation; import com.sequenceiq.cloudbreak.service.externaldatabase.DatabaseServerParameterDecorator; import com.sequenceiq.cloudbreak.service.externaldatabase.PollingConfig; diff --git a/core/src/main/java/com/sequenceiq/cloudbreak/core/flow2/service/ReactorFlowManager.java b/core/src/main/java/com/sequenceiq/cloudbreak/core/flow2/service/ReactorFlowManager.java index fcbe1636180..a1725871e50 100644 --- a/core/src/main/java/com/sequenceiq/cloudbreak/core/flow2/service/ReactorFlowManager.java +++ b/core/src/main/java/com/sequenceiq/cloudbreak/core/flow2/service/ReactorFlowManager.java @@ -86,15 +86,15 @@ import com.sequenceiq.cloudbreak.reactor.api.event.orchestration.StackRepairTriggerEvent; import com.sequenceiq.cloudbreak.reactor.api.event.stack.TerminationEvent; import com.sequenceiq.cloudbreak.reactor.api.event.stack.TerminationType; -import com.sequenceiq.cloudbreak.rotation.secret.RotationFlowExecutionType; -import com.sequenceiq.cloudbreak.rotation.secret.SecretType; +import com.sequenceiq.cloudbreak.rotation.RotationFlowExecutionType; +import com.sequenceiq.cloudbreak.rotation.SecretType; +import com.sequenceiq.cloudbreak.rotation.flow.chain.SecretRotationFlowChainTriggerEvent; import com.sequenceiq.cloudbreak.service.image.ImageChangeDto; import com.sequenceiq.cloudbreak.service.stack.StackService; import com.sequenceiq.cloudbreak.service.stack.repair.UnhealthyInstances; import com.sequenceiq.common.api.adjustment.AdjustmentTypeWithThreshold; import com.sequenceiq.flow.api.model.FlowIdentifier; import com.sequenceiq.flow.event.EventSelectorUtil; -import com.sequenceiq.flow.rotation.chain.SecretRotationFlowChainTriggerEvent; import com.sequenceiq.flow.service.FlowCancelService; /** diff --git a/core/src/main/java/com/sequenceiq/cloudbreak/rotation/CloudbreakSecretRotationInformation.java b/core/src/main/java/com/sequenceiq/cloudbreak/rotation/CloudbreakSecretRotationInformation.java index 109b24c2557..d3e312b3b8c 100644 --- a/core/src/main/java/com/sequenceiq/cloudbreak/rotation/CloudbreakSecretRotationInformation.java +++ b/core/src/main/java/com/sequenceiq/cloudbreak/rotation/CloudbreakSecretRotationInformation.java @@ -2,8 +2,7 @@ import org.springframework.stereotype.Component; -import com.sequenceiq.cloudbreak.rotation.secret.SecretType; -import com.sequenceiq.cloudbreak.rotation.secret.application.ApplicationSecretRotationInformation; +import com.sequenceiq.cloudbreak.rotation.config.ApplicationSecretRotationInformation; @Component public class CloudbreakSecretRotationInformation implements ApplicationSecretRotationInformation { diff --git a/core/src/main/java/com/sequenceiq/cloudbreak/rotation/context/CMServiceConfigRotationContext.java b/core/src/main/java/com/sequenceiq/cloudbreak/rotation/context/CMServiceConfigRotationContext.java index 4fdb97f855b..e2e4e406afb 100644 --- a/core/src/main/java/com/sequenceiq/cloudbreak/rotation/context/CMServiceConfigRotationContext.java +++ b/core/src/main/java/com/sequenceiq/cloudbreak/rotation/context/CMServiceConfigRotationContext.java @@ -1,7 +1,7 @@ package com.sequenceiq.cloudbreak.rotation.context; import com.google.common.collect.Table; -import com.sequenceiq.cloudbreak.rotation.secret.RotationContext; +import com.sequenceiq.cloudbreak.rotation.common.RotationContext; public class CMServiceConfigRotationContext extends RotationContext { diff --git a/core/src/main/java/com/sequenceiq/cloudbreak/rotation/context/CMUserRotationContext.java b/core/src/main/java/com/sequenceiq/cloudbreak/rotation/context/CMUserRotationContext.java index 1810b6904d1..e397b0db9fc 100644 --- a/core/src/main/java/com/sequenceiq/cloudbreak/rotation/context/CMUserRotationContext.java +++ b/core/src/main/java/com/sequenceiq/cloudbreak/rotation/context/CMUserRotationContext.java @@ -1,6 +1,6 @@ package com.sequenceiq.cloudbreak.rotation.context; -import com.sequenceiq.cloudbreak.rotation.secret.RotationContext; +import com.sequenceiq.cloudbreak.rotation.common.RotationContext; public class CMUserRotationContext extends RotationContext { diff --git a/core/src/main/java/com/sequenceiq/cloudbreak/rotation/context/ClusterProxyRotationContext.java b/core/src/main/java/com/sequenceiq/cloudbreak/rotation/context/ClusterProxyRotationContext.java index 84e59fc00fb..e3cc4e24dbf 100644 --- a/core/src/main/java/com/sequenceiq/cloudbreak/rotation/context/ClusterProxyRotationContext.java +++ b/core/src/main/java/com/sequenceiq/cloudbreak/rotation/context/ClusterProxyRotationContext.java @@ -1,6 +1,6 @@ package com.sequenceiq.cloudbreak.rotation.context; -import com.sequenceiq.cloudbreak.rotation.secret.RotationContext; +import com.sequenceiq.cloudbreak.rotation.common.RotationContext; public class ClusterProxyRotationContext extends RotationContext { diff --git a/core/src/main/java/com/sequenceiq/cloudbreak/rotation/context/SaltPillarRotationContext.java b/core/src/main/java/com/sequenceiq/cloudbreak/rotation/context/SaltPillarRotationContext.java index 62354a857de..0ad4e8e6435 100644 --- a/core/src/main/java/com/sequenceiq/cloudbreak/rotation/context/SaltPillarRotationContext.java +++ b/core/src/main/java/com/sequenceiq/cloudbreak/rotation/context/SaltPillarRotationContext.java @@ -4,7 +4,7 @@ import java.util.function.Function; import com.sequenceiq.cloudbreak.orchestrator.model.SaltPillarProperties; -import com.sequenceiq.cloudbreak.rotation.secret.RotationContext; +import com.sequenceiq.cloudbreak.rotation.common.RotationContext; public class SaltPillarRotationContext extends RotationContext { diff --git a/core/src/main/java/com/sequenceiq/cloudbreak/rotation/context/SaltStateApplyRotationContext.java b/core/src/main/java/com/sequenceiq/cloudbreak/rotation/context/SaltStateApplyRotationContext.java index d2312a8b852..baa3936151c 100644 --- a/core/src/main/java/com/sequenceiq/cloudbreak/rotation/context/SaltStateApplyRotationContext.java +++ b/core/src/main/java/com/sequenceiq/cloudbreak/rotation/context/SaltStateApplyRotationContext.java @@ -6,7 +6,7 @@ import com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig; import com.sequenceiq.cloudbreak.orchestrator.state.ExitCriteriaModel; -import com.sequenceiq.cloudbreak.rotation.secret.RotationContext; +import com.sequenceiq.cloudbreak.rotation.common.RotationContext; public class SaltStateApplyRotationContext extends RotationContext { diff --git a/core/src/main/java/com/sequenceiq/cloudbreak/rotation/context/provider/CBCMAdminPasswordRotationContextProvider.java b/core/src/main/java/com/sequenceiq/cloudbreak/rotation/context/provider/CBCMAdminPasswordRotationContextProvider.java index 9b5c656f6ab..f479dc0f7c3 100644 --- a/core/src/main/java/com/sequenceiq/cloudbreak/rotation/context/provider/CBCMAdminPasswordRotationContextProvider.java +++ b/core/src/main/java/com/sequenceiq/cloudbreak/rotation/context/provider/CBCMAdminPasswordRotationContextProvider.java @@ -5,7 +5,7 @@ import org.springframework.stereotype.Component; import com.sequenceiq.cloudbreak.rotation.CloudbreakSecretType; -import com.sequenceiq.cloudbreak.rotation.secret.SecretType; +import com.sequenceiq.cloudbreak.rotation.SecretType; import com.sequenceiq.cloudbreak.service.secret.domain.Secret; import com.sequenceiq.cloudbreak.view.ClusterView; diff --git a/core/src/main/java/com/sequenceiq/cloudbreak/rotation/context/provider/CMDBPasswordRotationContextProvider.java b/core/src/main/java/com/sequenceiq/cloudbreak/rotation/context/provider/CMDBPasswordRotationContextProvider.java index ed0679f07b0..287abc84393 100644 --- a/core/src/main/java/com/sequenceiq/cloudbreak/rotation/context/provider/CMDBPasswordRotationContextProvider.java +++ b/core/src/main/java/com/sequenceiq/cloudbreak/rotation/context/provider/CMDBPasswordRotationContextProvider.java @@ -2,8 +2,8 @@ import static com.sequenceiq.cloudbreak.rotation.CloudbreakSecretRotationStep.SALT_PILLAR; import static com.sequenceiq.cloudbreak.rotation.CloudbreakSecretRotationStep.SALT_STATE_APPLY; -import static com.sequenceiq.cloudbreak.rotation.secret.step.CommonSecretRotationStep.CUSTOM_JOB; -import static com.sequenceiq.cloudbreak.rotation.secret.step.CommonSecretRotationStep.VAULT; +import static com.sequenceiq.cloudbreak.rotation.CommonSecretRotationStep.CUSTOM_JOB; +import static com.sequenceiq.cloudbreak.rotation.CommonSecretRotationStep.VAULT; import java.text.SimpleDateFormat; import java.util.Date; @@ -29,14 +29,14 @@ import com.sequenceiq.cloudbreak.orchestrator.model.SaltPillarProperties; import com.sequenceiq.cloudbreak.rotation.CloudbreakSecretType; import com.sequenceiq.cloudbreak.rotation.ExitCriteriaProvider; +import com.sequenceiq.cloudbreak.rotation.SecretRotationStep; +import com.sequenceiq.cloudbreak.rotation.SecretType; +import com.sequenceiq.cloudbreak.rotation.common.RotationContext; +import com.sequenceiq.cloudbreak.rotation.common.RotationContextProvider; +import com.sequenceiq.cloudbreak.rotation.common.SecretRotationException; import com.sequenceiq.cloudbreak.rotation.context.SaltPillarRotationContext; import com.sequenceiq.cloudbreak.rotation.context.SaltStateApplyRotationContext; -import com.sequenceiq.cloudbreak.rotation.secret.RotationContext; -import com.sequenceiq.cloudbreak.rotation.secret.RotationContextProvider; -import com.sequenceiq.cloudbreak.rotation.secret.SecretRotationException; -import com.sequenceiq.cloudbreak.rotation.secret.SecretType; -import com.sequenceiq.cloudbreak.rotation.secret.context.CustomJobRotationContext; -import com.sequenceiq.cloudbreak.rotation.secret.step.SecretRotationStep; +import com.sequenceiq.cloudbreak.rotation.secret.custom.CustomJobRotationContext; import com.sequenceiq.cloudbreak.rotation.secret.vault.VaultRotationContext; import com.sequenceiq.cloudbreak.service.GatewayConfigService; import com.sequenceiq.cloudbreak.service.cluster.ClusterApiConnectors; diff --git a/core/src/main/java/com/sequenceiq/cloudbreak/rotation/context/provider/CMServiceDBPasswordRotationContextProvider.java b/core/src/main/java/com/sequenceiq/cloudbreak/rotation/context/provider/CMServiceDBPasswordRotationContextProvider.java index 42ac3b7ac35..7703d66295a 100644 --- a/core/src/main/java/com/sequenceiq/cloudbreak/rotation/context/provider/CMServiceDBPasswordRotationContextProvider.java +++ b/core/src/main/java/com/sequenceiq/cloudbreak/rotation/context/provider/CMServiceDBPasswordRotationContextProvider.java @@ -4,7 +4,7 @@ import static com.sequenceiq.cloudbreak.rotation.CloudbreakSecretRotationStep.SALT_PILLAR; import static com.sequenceiq.cloudbreak.rotation.CloudbreakSecretRotationStep.SALT_STATE_APPLY; import static com.sequenceiq.cloudbreak.rotation.CloudbreakSecretType.CLUSTER_CM_SERVICES_DB_PASSWORD; -import static com.sequenceiq.cloudbreak.rotation.secret.step.CommonSecretRotationStep.VAULT; +import static com.sequenceiq.cloudbreak.rotation.CommonSecretRotationStep.VAULT; import java.text.SimpleDateFormat; import java.util.Arrays; @@ -34,13 +34,13 @@ import com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig; import com.sequenceiq.cloudbreak.orchestrator.model.SaltPillarProperties; import com.sequenceiq.cloudbreak.rotation.ExitCriteriaProvider; +import com.sequenceiq.cloudbreak.rotation.SecretRotationStep; +import com.sequenceiq.cloudbreak.rotation.SecretType; +import com.sequenceiq.cloudbreak.rotation.common.RotationContext; +import com.sequenceiq.cloudbreak.rotation.common.RotationContextProvider; import com.sequenceiq.cloudbreak.rotation.context.CMServiceConfigRotationContext; import com.sequenceiq.cloudbreak.rotation.context.SaltPillarRotationContext; import com.sequenceiq.cloudbreak.rotation.context.SaltStateApplyRotationContext; -import com.sequenceiq.cloudbreak.rotation.secret.RotationContext; -import com.sequenceiq.cloudbreak.rotation.secret.RotationContextProvider; -import com.sequenceiq.cloudbreak.rotation.secret.SecretType; -import com.sequenceiq.cloudbreak.rotation.secret.step.SecretRotationStep; import com.sequenceiq.cloudbreak.rotation.secret.vault.VaultRotationContext; import com.sequenceiq.cloudbreak.service.GatewayConfigService; import com.sequenceiq.cloudbreak.service.rdsconfig.AbstractRdsConfigProvider; diff --git a/core/src/main/java/com/sequenceiq/cloudbreak/rotation/context/provider/CMUserRotationContextProvider.java b/core/src/main/java/com/sequenceiq/cloudbreak/rotation/context/provider/CMUserRotationContextProvider.java index 097d032885c..7cf957da84c 100644 --- a/core/src/main/java/com/sequenceiq/cloudbreak/rotation/context/provider/CMUserRotationContextProvider.java +++ b/core/src/main/java/com/sequenceiq/cloudbreak/rotation/context/provider/CMUserRotationContextProvider.java @@ -11,12 +11,12 @@ import com.google.common.collect.Maps; import com.sequenceiq.cloudbreak.dto.StackDto; import com.sequenceiq.cloudbreak.rotation.CloudbreakSecretRotationStep; +import com.sequenceiq.cloudbreak.rotation.CommonSecretRotationStep; +import com.sequenceiq.cloudbreak.rotation.SecretRotationStep; +import com.sequenceiq.cloudbreak.rotation.common.RotationContext; +import com.sequenceiq.cloudbreak.rotation.common.RotationContextProvider; import com.sequenceiq.cloudbreak.rotation.context.CMUserRotationContext; import com.sequenceiq.cloudbreak.rotation.context.ClusterProxyRotationContext; -import com.sequenceiq.cloudbreak.rotation.secret.RotationContext; -import com.sequenceiq.cloudbreak.rotation.secret.RotationContextProvider; -import com.sequenceiq.cloudbreak.rotation.secret.step.CommonSecretRotationStep; -import com.sequenceiq.cloudbreak.rotation.secret.step.SecretRotationStep; import com.sequenceiq.cloudbreak.rotation.secret.vault.VaultRotationContext; import com.sequenceiq.cloudbreak.service.secret.domain.Secret; import com.sequenceiq.cloudbreak.service.stack.StackDtoService; diff --git a/core/src/main/java/com/sequenceiq/cloudbreak/rotation/context/provider/DatahubExternalDatabaseRootPasswordRotationContextProvider.java b/core/src/main/java/com/sequenceiq/cloudbreak/rotation/context/provider/DatahubExternalDatabaseRootPasswordRotationContextProvider.java index b4df7c9daa6..dbc5304b5df 100644 --- a/core/src/main/java/com/sequenceiq/cloudbreak/rotation/context/provider/DatahubExternalDatabaseRootPasswordRotationContextProvider.java +++ b/core/src/main/java/com/sequenceiq/cloudbreak/rotation/context/provider/DatahubExternalDatabaseRootPasswordRotationContextProvider.java @@ -2,7 +2,7 @@ import static com.sequenceiq.cloudbreak.rotation.CloudbreakSecretRotationStep.SALT_PILLAR; import static com.sequenceiq.cloudbreak.rotation.CloudbreakSecretType.DATAHUB_EXTERNAL_DATABASE_ROOT_PASSWORD; -import static com.sequenceiq.cloudbreak.rotation.secret.step.CommonSecretRotationStep.REDBEAMS_ROTATE_POLLING; +import static com.sequenceiq.cloudbreak.rotation.CommonSecretRotationStep.REDBEAMS_ROTATE_POLLING; import static com.sequenceiq.redbeams.rotation.RedbeamsSecretType.REDBEAMS_EXTERNAL_DATABASE_ROOT_PASSWORD; import java.util.HashMap; @@ -13,12 +13,12 @@ import org.springframework.stereotype.Component; import com.sequenceiq.cloudbreak.rotation.DatabaseRootPasswordSaltPillarGenerator; +import com.sequenceiq.cloudbreak.rotation.SecretRotationStep; +import com.sequenceiq.cloudbreak.rotation.SecretType; +import com.sequenceiq.cloudbreak.rotation.common.RotationContext; +import com.sequenceiq.cloudbreak.rotation.common.RotationContextProvider; import com.sequenceiq.cloudbreak.rotation.context.SaltPillarRotationContext; -import com.sequenceiq.cloudbreak.rotation.secret.RotationContext; -import com.sequenceiq.cloudbreak.rotation.secret.RotationContextProvider; -import com.sequenceiq.cloudbreak.rotation.secret.SecretType; -import com.sequenceiq.cloudbreak.rotation.secret.context.PollerRotationContext; -import com.sequenceiq.cloudbreak.rotation.secret.step.SecretRotationStep; +import com.sequenceiq.cloudbreak.rotation.secret.poller.PollerRotationContext; @Component public class DatahubExternalDatabaseRootPasswordRotationContextProvider implements RotationContextProvider { diff --git a/core/src/main/java/com/sequenceiq/cloudbreak/rotation/context/provider/DatalakeExternalDatabaseRootPasswordRotationContextProvider.java b/core/src/main/java/com/sequenceiq/cloudbreak/rotation/context/provider/DatalakeExternalDatabaseRootPasswordRotationContextProvider.java index 11954789aa2..3a8e78972eb 100644 --- a/core/src/main/java/com/sequenceiq/cloudbreak/rotation/context/provider/DatalakeExternalDatabaseRootPasswordRotationContextProvider.java +++ b/core/src/main/java/com/sequenceiq/cloudbreak/rotation/context/provider/DatalakeExternalDatabaseRootPasswordRotationContextProvider.java @@ -11,11 +11,11 @@ import com.sequenceiq.cloudbreak.rotation.CloudbreakSecretRotationStep; import com.sequenceiq.cloudbreak.rotation.DatabaseRootPasswordSaltPillarGenerator; +import com.sequenceiq.cloudbreak.rotation.SecretRotationStep; +import com.sequenceiq.cloudbreak.rotation.SecretType; +import com.sequenceiq.cloudbreak.rotation.common.RotationContext; +import com.sequenceiq.cloudbreak.rotation.common.RotationContextProvider; import com.sequenceiq.cloudbreak.rotation.context.SaltPillarRotationContext; -import com.sequenceiq.cloudbreak.rotation.secret.RotationContext; -import com.sequenceiq.cloudbreak.rotation.secret.RotationContextProvider; -import com.sequenceiq.cloudbreak.rotation.secret.SecretType; -import com.sequenceiq.cloudbreak.rotation.secret.step.SecretRotationStep; @Component public class DatalakeExternalDatabaseRootPasswordRotationContextProvider implements RotationContextProvider { diff --git a/core/src/main/java/com/sequenceiq/cloudbreak/rotation/context/provider/MgmtCMAdminPasswordRotationContextProvider.java b/core/src/main/java/com/sequenceiq/cloudbreak/rotation/context/provider/MgmtCMAdminPasswordRotationContextProvider.java index daf498e544a..da50f04fabb 100644 --- a/core/src/main/java/com/sequenceiq/cloudbreak/rotation/context/provider/MgmtCMAdminPasswordRotationContextProvider.java +++ b/core/src/main/java/com/sequenceiq/cloudbreak/rotation/context/provider/MgmtCMAdminPasswordRotationContextProvider.java @@ -5,7 +5,7 @@ import org.springframework.stereotype.Component; import com.sequenceiq.cloudbreak.rotation.CloudbreakSecretType; -import com.sequenceiq.cloudbreak.rotation.secret.SecretType; +import com.sequenceiq.cloudbreak.rotation.SecretType; import com.sequenceiq.cloudbreak.service.secret.domain.Secret; import com.sequenceiq.cloudbreak.view.ClusterView; diff --git a/core/src/main/java/com/sequenceiq/cloudbreak/rotation/saltboot/SaltBootRotationContextProvider.java b/core/src/main/java/com/sequenceiq/cloudbreak/rotation/context/provider/SaltBootRotationContextProvider.java similarity index 79% rename from core/src/main/java/com/sequenceiq/cloudbreak/rotation/saltboot/SaltBootRotationContextProvider.java rename to core/src/main/java/com/sequenceiq/cloudbreak/rotation/context/provider/SaltBootRotationContextProvider.java index 6d673670d5c..ec09c393e5e 100644 --- a/core/src/main/java/com/sequenceiq/cloudbreak/rotation/saltboot/SaltBootRotationContextProvider.java +++ b/core/src/main/java/com/sequenceiq/cloudbreak/rotation/context/provider/SaltBootRotationContextProvider.java @@ -1,9 +1,9 @@ -package com.sequenceiq.cloudbreak.rotation.saltboot; +package com.sequenceiq.cloudbreak.rotation.context.provider; -import static com.sequenceiq.cloudbreak.rotation.secret.step.CommonSecretRotationStep.CUSTOM_JOB; -import static com.sequenceiq.cloudbreak.rotation.secret.step.CommonSecretRotationStep.SERVICE_CONFIG; -import static com.sequenceiq.cloudbreak.rotation.secret.step.CommonSecretRotationStep.USER_DATA; -import static com.sequenceiq.cloudbreak.rotation.secret.step.CommonSecretRotationStep.VAULT; +import static com.sequenceiq.cloudbreak.rotation.CommonSecretRotationStep.CUSTOM_JOB; +import static com.sequenceiq.cloudbreak.rotation.CommonSecretRotationStep.SALTBOOT_CONFIG; +import static com.sequenceiq.cloudbreak.rotation.CommonSecretRotationStep.USER_DATA; +import static com.sequenceiq.cloudbreak.rotation.CommonSecretRotationStep.VAULT; import java.security.PublicKey; import java.util.List; @@ -19,20 +19,20 @@ import com.google.common.collect.ImmutableMap; import com.google.common.io.BaseEncoding; import com.sequenceiq.cloudbreak.certificate.PkiUtil; -import com.sequenceiq.cloudbreak.cloud.rotation.UserDataRotationContext; import com.sequenceiq.cloudbreak.core.bootstrap.service.ClusterDeletionBasedExitCriteriaModel; import com.sequenceiq.cloudbreak.domain.SaltSecurityConfig; import com.sequenceiq.cloudbreak.dto.StackDto; -import com.sequenceiq.cloudbreak.orchestrator.rotation.ServiceConfigRotationContext; -import com.sequenceiq.cloudbreak.orchestrator.rotation.ServiceUpdateConfiguration; -import com.sequenceiq.cloudbreak.orchestrator.salt.rotation.SaltBootPasswordUserDataModifier; -import com.sequenceiq.cloudbreak.orchestrator.salt.rotation.SaltBootSignKeyUserDataModifier; import com.sequenceiq.cloudbreak.rotation.CloudbreakSecretType; -import com.sequenceiq.cloudbreak.rotation.secret.RotationContext; -import com.sequenceiq.cloudbreak.rotation.secret.RotationContextProvider; -import com.sequenceiq.cloudbreak.rotation.secret.SecretType; -import com.sequenceiq.cloudbreak.rotation.secret.context.CustomJobRotationContext; -import com.sequenceiq.cloudbreak.rotation.secret.step.SecretRotationStep; +import com.sequenceiq.cloudbreak.rotation.SecretRotationStep; +import com.sequenceiq.cloudbreak.rotation.SecretType; +import com.sequenceiq.cloudbreak.rotation.common.RotationContext; +import com.sequenceiq.cloudbreak.rotation.common.RotationContextProvider; +import com.sequenceiq.cloudbreak.rotation.context.saltboot.SaltBootConfigRotationContext; +import com.sequenceiq.cloudbreak.rotation.context.saltboot.SaltBootUpdateConfiguration; +import com.sequenceiq.cloudbreak.rotation.secret.custom.CustomJobRotationContext; +import com.sequenceiq.cloudbreak.rotation.secret.saltboot.SaltBootPasswordUserDataModifier; +import com.sequenceiq.cloudbreak.rotation.secret.saltboot.SaltBootSignKeyUserDataModifier; +import com.sequenceiq.cloudbreak.rotation.secret.userdata.UserDataRotationContext; import com.sequenceiq.cloudbreak.rotation.secret.vault.VaultRotationContext; import com.sequenceiq.cloudbreak.service.GatewayConfigService; import com.sequenceiq.cloudbreak.service.saltsecurityconf.SaltSecurityConfigService; @@ -82,9 +82,9 @@ public Map getContexts(String resourceId) { Secret saltBootPasswordSecret = saltSecurityConfig.getSaltBootPasswordSecret(); Secret saltBootPrivateKeySecret = saltSecurityConfig.getSaltBootSignPrivateKeySecret(); return ImmutableMap.builder() - .put(VAULT, getVaultRotationContext(saltBootPasswordSecret, saltBootPrivateKeySecret)) + .put(VAULT, getVaultRotationContext(resourceId, saltBootPasswordSecret, saltBootPrivateKeySecret)) .put(CUSTOM_JOB, getSaltPublicKeyUpdateJob(resourceId, saltBootPrivateKeySecret.getSecret())) - .put(SERVICE_CONFIG, getSaltBootRotationContext(stack, saltBootPasswordSecret, saltBootPrivateKeySecret)) + .put(SALTBOOT_CONFIG, getSaltBootRotationContext(stack, saltBootPasswordSecret, saltBootPrivateKeySecret)) .put(USER_DATA, getUserDataRotationContext(stack, saltBootPasswordSecret, saltBootPrivateKeySecret)) .build(); } @@ -118,18 +118,18 @@ private UserDataRotationContext getUserDataRotationContext(StackDto stack, Secre Pair.of(saltBootSignKeyUserDataModifier, saltBootPrivateKeySecret.getSecret()))); } - private ServiceConfigRotationContext getSaltBootRotationContext(StackDto stack, Secret saltBootPasswordSecret, Secret saltBootPrivateKeySecret) { - return new ServiceConfigRotationContext(stack.getResourceCrn()) { + private SaltBootConfigRotationContext getSaltBootRotationContext(StackDto stack, Secret saltBootPasswordSecret, Secret saltBootPrivateKeySecret) { + return new SaltBootConfigRotationContext(stack.getResourceCrn()) { @Override - public ServiceUpdateConfiguration getServiceUpdateConfiguration() { + public SaltBootUpdateConfiguration getServiceUpdateConfiguration() { RotationSecret saltBootPassword = secretService.getRotation(saltBootPasswordSecret.getSecret()); RotationSecret saltBootPrivateKey = secretService.getRotation(saltBootPrivateKeySecret.getSecret()); String oldSaltBootPassword = saltBootPassword.isRotation() ? saltBootPassword.getBackupSecret() : saltBootPassword.getSecret(); String newSaltBootPassword = saltBootPassword.getSecret(); String oldSaltBootPrivateKey = saltBootPrivateKey.isRotation() ? saltBootPrivateKey.getBackupSecret() : saltBootPrivateKey.getSecret(); String newSaltBootPrivateKey = saltBootPrivateKey.getSecret(); - return new ServiceUpdateConfiguration( + return new SaltBootUpdateConfiguration( gatewayConfigService.getPrimaryGatewayConfig(stack), oldSaltBootPassword, newSaltBootPassword, @@ -162,8 +162,9 @@ private String generateSaltBootSecretConfig(String password, String privateKey) .replace("$PUBLIC_KEY", BASE64.encode(PkiUtil.getPublicKeyDer(new String(BASE64.decode(privateKey))))); } - private VaultRotationContext getVaultRotationContext(Secret saltBootPasswordSecret, Secret saltBootPrivateKeySecret) { + private VaultRotationContext getVaultRotationContext(String resourceCrn, Secret saltBootPasswordSecret, Secret saltBootPrivateKeySecret) { return VaultRotationContext.builder() + .withResourceCrn(resourceCrn) .withVaultPathSecretMap(ImmutableMap.builder() .put(saltBootPasswordSecret.getSecret(), PasswordUtil.generatePassword()) .put(saltBootPrivateKeySecret.getSecret(), diff --git a/core/src/main/java/com/sequenceiq/cloudbreak/rotation/context/provider/UserKeyPairRotationContextProvider.java b/core/src/main/java/com/sequenceiq/cloudbreak/rotation/context/provider/UserKeyPairRotationContextProvider.java index e71c23e65e4..0ec2a4a529f 100644 --- a/core/src/main/java/com/sequenceiq/cloudbreak/rotation/context/provider/UserKeyPairRotationContextProvider.java +++ b/core/src/main/java/com/sequenceiq/cloudbreak/rotation/context/provider/UserKeyPairRotationContextProvider.java @@ -16,13 +16,12 @@ import com.sequenceiq.cloudbreak.repository.StackAuthenticationRepository; import com.sequenceiq.cloudbreak.rotation.CloudbreakSecretRotationStep; import com.sequenceiq.cloudbreak.rotation.CloudbreakSecretType; -import com.sequenceiq.cloudbreak.rotation.secret.RotationContext; -import com.sequenceiq.cloudbreak.rotation.secret.RotationContextProvider; -import com.sequenceiq.cloudbreak.rotation.secret.SecretType; -import com.sequenceiq.cloudbreak.rotation.secret.context.CustomJobRotationContext; -import com.sequenceiq.cloudbreak.rotation.secret.context.CustomJobRotationContext.CustomJobRotationContextBuilder; -import com.sequenceiq.cloudbreak.rotation.secret.step.CommonSecretRotationStep; -import com.sequenceiq.cloudbreak.rotation.secret.step.SecretRotationStep; +import com.sequenceiq.cloudbreak.rotation.CommonSecretRotationStep; +import com.sequenceiq.cloudbreak.rotation.SecretRotationStep; +import com.sequenceiq.cloudbreak.rotation.SecretType; +import com.sequenceiq.cloudbreak.rotation.common.RotationContext; +import com.sequenceiq.cloudbreak.rotation.common.RotationContextProvider; +import com.sequenceiq.cloudbreak.rotation.secret.custom.CustomJobRotationContext; import com.sequenceiq.cloudbreak.service.environment.EnvironmentClientService; import com.sequenceiq.cloudbreak.service.stack.StackDtoService; import com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse; @@ -66,7 +65,7 @@ public Map getContexts(String resourceId) { private CustomJobRotationContext getCustomJobRotationContext(boolean changedKeyPair, String resourceCrn, StackDto stack, DetailedEnvironmentResponse environment) { - CustomJobRotationContextBuilder customJobRotationContextBuilder = CustomJobRotationContext.builder(); + CustomJobRotationContext.CustomJobRotationContextBuilder customJobRotationContextBuilder = CustomJobRotationContext.builder(); customJobRotationContextBuilder.withResourceCrn(resourceCrn); if (changedKeyPair) { customJobRotationContextBuilder.withRotationJob(() -> stackAuthenticationRepository diff --git a/core/src/main/java/com/sequenceiq/cloudbreak/rotation/context/saltboot/SaltBootConfigRotationContext.java b/core/src/main/java/com/sequenceiq/cloudbreak/rotation/context/saltboot/SaltBootConfigRotationContext.java new file mode 100644 index 00000000000..1c4d3b578df --- /dev/null +++ b/core/src/main/java/com/sequenceiq/cloudbreak/rotation/context/saltboot/SaltBootConfigRotationContext.java @@ -0,0 +1,12 @@ +package com.sequenceiq.cloudbreak.rotation.context.saltboot; + +import com.sequenceiq.cloudbreak.rotation.common.RotationContext; + +public abstract class SaltBootConfigRotationContext extends RotationContext { + + public SaltBootConfigRotationContext(String resourceCrn) { + super(resourceCrn); + } + + public abstract SaltBootUpdateConfiguration getServiceUpdateConfiguration(); +} diff --git a/orchestrator-api/src/main/java/com/sequenceiq/cloudbreak/orchestrator/rotation/ServiceUpdateConfiguration.java b/core/src/main/java/com/sequenceiq/cloudbreak/rotation/context/saltboot/SaltBootUpdateConfiguration.java similarity index 86% rename from orchestrator-api/src/main/java/com/sequenceiq/cloudbreak/orchestrator/rotation/ServiceUpdateConfiguration.java rename to core/src/main/java/com/sequenceiq/cloudbreak/rotation/context/saltboot/SaltBootUpdateConfiguration.java index 152af954710..095c5fc8e27 100644 --- a/orchestrator-api/src/main/java/com/sequenceiq/cloudbreak/orchestrator/rotation/ServiceUpdateConfiguration.java +++ b/core/src/main/java/com/sequenceiq/cloudbreak/rotation/context/saltboot/SaltBootUpdateConfiguration.java @@ -1,4 +1,4 @@ -package com.sequenceiq.cloudbreak.orchestrator.rotation; +package com.sequenceiq.cloudbreak.rotation.context.saltboot; import java.util.List; import java.util.Set; @@ -6,7 +6,7 @@ import com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig; import com.sequenceiq.cloudbreak.orchestrator.state.ExitCriteriaModel; -public record ServiceUpdateConfiguration( +public record SaltBootUpdateConfiguration( GatewayConfig primaryGatewayConfig, String oldSaltBootPassword, String newSaltBootPassword, diff --git a/core/src/main/java/com/sequenceiq/cloudbreak/rotation/executor/CMServiceConfigRotationExecutor.java b/core/src/main/java/com/sequenceiq/cloudbreak/rotation/executor/CMServiceConfigRotationExecutor.java index 4f70785f880..e0bf3b40466 100644 --- a/core/src/main/java/com/sequenceiq/cloudbreak/rotation/executor/CMServiceConfigRotationExecutor.java +++ b/core/src/main/java/com/sequenceiq/cloudbreak/rotation/executor/CMServiceConfigRotationExecutor.java @@ -9,9 +9,8 @@ import org.springframework.stereotype.Component; import com.sequenceiq.cloudbreak.dto.StackDto; +import com.sequenceiq.cloudbreak.rotation.SecretRotationStep; import com.sequenceiq.cloudbreak.rotation.context.CMServiceConfigRotationContext; -import com.sequenceiq.cloudbreak.rotation.secret.AbstractRotationExecutor; -import com.sequenceiq.cloudbreak.rotation.secret.step.SecretRotationStep; import com.sequenceiq.cloudbreak.service.cluster.ClusterApiConnectors; import com.sequenceiq.cloudbreak.service.secret.service.SecretService; import com.sequenceiq.cloudbreak.service.stack.StackDtoService; diff --git a/core/src/main/java/com/sequenceiq/cloudbreak/rotation/executor/CMUserRotationExecutor.java b/core/src/main/java/com/sequenceiq/cloudbreak/rotation/executor/CMUserRotationExecutor.java index db8727c4225..9912aa71b03 100644 --- a/core/src/main/java/com/sequenceiq/cloudbreak/rotation/executor/CMUserRotationExecutor.java +++ b/core/src/main/java/com/sequenceiq/cloudbreak/rotation/executor/CMUserRotationExecutor.java @@ -9,11 +9,10 @@ import com.sequenceiq.cloudbreak.cluster.api.ClusterSecurityService; import com.sequenceiq.cloudbreak.dto.StackDto; import com.sequenceiq.cloudbreak.rotation.CloudbreakSecretRotationStep; +import com.sequenceiq.cloudbreak.rotation.SecretRotationStep; +import com.sequenceiq.cloudbreak.rotation.common.RotationContext; +import com.sequenceiq.cloudbreak.rotation.common.SecretRotationException; import com.sequenceiq.cloudbreak.rotation.context.CMUserRotationContext; -import com.sequenceiq.cloudbreak.rotation.secret.AbstractRotationExecutor; -import com.sequenceiq.cloudbreak.rotation.secret.RotationContext; -import com.sequenceiq.cloudbreak.rotation.secret.SecretRotationException; -import com.sequenceiq.cloudbreak.rotation.secret.step.SecretRotationStep; import com.sequenceiq.cloudbreak.service.CloudbreakException; import com.sequenceiq.cloudbreak.service.cluster.ClusterApiConnectors; import com.sequenceiq.cloudbreak.service.secret.domain.RotationSecret; diff --git a/core/src/main/java/com/sequenceiq/cloudbreak/rotation/executor/ClusterProxyRotationExecutor.java b/core/src/main/java/com/sequenceiq/cloudbreak/rotation/executor/ClusterProxyRotationExecutor.java index be46072f28f..64dc2354384 100644 --- a/core/src/main/java/com/sequenceiq/cloudbreak/rotation/executor/ClusterProxyRotationExecutor.java +++ b/core/src/main/java/com/sequenceiq/cloudbreak/rotation/executor/ClusterProxyRotationExecutor.java @@ -9,9 +9,8 @@ import com.sequenceiq.cloudbreak.core.flow2.cluster.provision.service.ClusterProxyService; import com.sequenceiq.cloudbreak.dto.StackDto; import com.sequenceiq.cloudbreak.rotation.CloudbreakSecretRotationStep; +import com.sequenceiq.cloudbreak.rotation.SecretRotationStep; import com.sequenceiq.cloudbreak.rotation.context.ClusterProxyRotationContext; -import com.sequenceiq.cloudbreak.rotation.secret.AbstractRotationExecutor; -import com.sequenceiq.cloudbreak.rotation.secret.step.SecretRotationStep; import com.sequenceiq.cloudbreak.service.stack.StackDtoService; @Component diff --git a/core/src/main/java/com/sequenceiq/cloudbreak/rotation/executor/RedbeamsPollerRotationExecutor.java b/core/src/main/java/com/sequenceiq/cloudbreak/rotation/executor/RedbeamsPollerRotationExecutor.java index ab7e051748d..6c93c062be1 100644 --- a/core/src/main/java/com/sequenceiq/cloudbreak/rotation/executor/RedbeamsPollerRotationExecutor.java +++ b/core/src/main/java/com/sequenceiq/cloudbreak/rotation/executor/RedbeamsPollerRotationExecutor.java @@ -1,9 +1,9 @@ package com.sequenceiq.cloudbreak.rotation.executor; -import static com.sequenceiq.cloudbreak.rotation.secret.RotationFlowExecutionType.FINALIZE; -import static com.sequenceiq.cloudbreak.rotation.secret.RotationFlowExecutionType.ROLLBACK; -import static com.sequenceiq.cloudbreak.rotation.secret.RotationFlowExecutionType.ROTATE; -import static com.sequenceiq.cloudbreak.rotation.secret.step.CommonSecretRotationStep.REDBEAMS_ROTATE_POLLING; +import static com.sequenceiq.cloudbreak.rotation.CommonSecretRotationStep.REDBEAMS_ROTATE_POLLING; +import static com.sequenceiq.cloudbreak.rotation.RotationFlowExecutionType.FINALIZE; +import static com.sequenceiq.cloudbreak.rotation.RotationFlowExecutionType.ROLLBACK; +import static com.sequenceiq.cloudbreak.rotation.RotationFlowExecutionType.ROTATE; import javax.inject.Inject; @@ -13,9 +13,8 @@ import com.sequenceiq.cloudbreak.core.flow2.externaldatabase.ExternalDatabaseService; import com.sequenceiq.cloudbreak.dto.StackDto; -import com.sequenceiq.cloudbreak.rotation.secret.AbstractRotationExecutor; -import com.sequenceiq.cloudbreak.rotation.secret.context.PollerRotationContext; -import com.sequenceiq.cloudbreak.rotation.secret.step.SecretRotationStep; +import com.sequenceiq.cloudbreak.rotation.SecretRotationStep; +import com.sequenceiq.cloudbreak.rotation.secret.poller.PollerRotationContext; import com.sequenceiq.cloudbreak.service.stack.StackDtoService; import com.sequenceiq.redbeams.rotation.RedbeamsSecretType; diff --git a/core/src/main/java/com/sequenceiq/cloudbreak/rotation/executor/SaltBootConfigRotationExecutor.java b/core/src/main/java/com/sequenceiq/cloudbreak/rotation/executor/SaltBootConfigRotationExecutor.java new file mode 100644 index 00000000000..8afa55b21cb --- /dev/null +++ b/core/src/main/java/com/sequenceiq/cloudbreak/rotation/executor/SaltBootConfigRotationExecutor.java @@ -0,0 +1,160 @@ +package com.sequenceiq.cloudbreak.rotation.executor; + +import static com.sequenceiq.cloudbreak.rotation.CommonSecretRotationStep.SALTBOOT_CONFIG; + +import java.nio.charset.StandardCharsets; +import java.util.Optional; + +import javax.inject.Inject; + +import org.apache.commons.collections4.CollectionUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Component; + +import com.google.common.io.BaseEncoding; +import com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException; +import com.sequenceiq.cloudbreak.orchestrator.host.HostOrchestrator; +import com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig; +import com.sequenceiq.cloudbreak.rotation.SecretRotationStep; +import com.sequenceiq.cloudbreak.rotation.common.SecretRotationException; +import com.sequenceiq.cloudbreak.rotation.context.saltboot.SaltBootConfigRotationContext; +import com.sequenceiq.cloudbreak.rotation.context.saltboot.SaltBootUpdateConfiguration; + +@Component +public class SaltBootConfigRotationExecutor extends AbstractRotationExecutor { + + private static final Logger LOGGER = LoggerFactory.getLogger(SaltBootConfigRotationExecutor.class); + + private static final BaseEncoding BASE64 = BaseEncoding.base64(); + + @Inject + private HostOrchestrator hostOrchestrator; + + @Override + public void rotate(SaltBootConfigRotationContext rotationContext) { + SaltBootUpdateConfiguration saltBootUpdateConfiguration = rotationContext.getServiceUpdateConfiguration(); + GatewayConfig gatewayConfig = getUsableGatewayConfig(saltBootUpdateConfiguration); + uploadFile(saltBootUpdateConfiguration, gatewayConfig, saltBootUpdateConfiguration.newConfig()); + restartSaltBootService(saltBootUpdateConfiguration, gatewayConfig); + } + + @Override + public void rollback(SaltBootConfigRotationContext rotationContext) { + SaltBootUpdateConfiguration saltBootUpdateConfiguration = rotationContext.getServiceUpdateConfiguration(); + GatewayConfig gatewayConfig = getUsableGatewayConfig(saltBootUpdateConfiguration); + uploadFile(saltBootUpdateConfiguration, gatewayConfig, saltBootUpdateConfiguration.oldConfig()); + restartSaltBootService(saltBootUpdateConfiguration, gatewayConfig); + } + + @Override + public void finalize(SaltBootConfigRotationContext rotationContext) { + + } + + @Override + public void preValidate(SaltBootConfigRotationContext rotationContext) throws Exception { + + } + + @Override + public void postValidate(SaltBootConfigRotationContext rotationContext) throws Exception { + + } + + @Override + public SecretRotationStep getType() { + return SALTBOOT_CONFIG; + } + + @Override + public Class getContextClass() { + return SaltBootConfigRotationContext.class; + } + + private GatewayConfig getUsableGatewayConfig(SaltBootUpdateConfiguration saltBootUpdateConfiguration) { + GatewayConfig oldPrimaryGatewayConfig = withOldSecrets(saltBootUpdateConfiguration.primaryGatewayConfig(), saltBootUpdateConfiguration); + LOGGER.info("Checking if salt boot is reachable with old secrets."); + if (isSaltBootReachableWithGatewayConfig(saltBootUpdateConfiguration, oldPrimaryGatewayConfig)) { + LOGGER.info("Using old salt boot credentials for file upload."); + return oldPrimaryGatewayConfig; + } + GatewayConfig newPrimaryGatewayConfig = withNewSecrets(saltBootUpdateConfiguration.primaryGatewayConfig(), saltBootUpdateConfiguration); + if (isSaltBootReachableWithGatewayConfig(saltBootUpdateConfiguration, newPrimaryGatewayConfig)) { + LOGGER.info("Using new salt boot credentials for file upload."); + return newPrimaryGatewayConfig; + } + throw new SecretRotationException(String.format( + "Salt boot is not reachable with old nor with new secrets. %s/%s service config can't be updated.", + saltBootUpdateConfiguration.configFolder(), saltBootUpdateConfiguration.configFile()), + getType()); + } + + private boolean isSaltBootReachableWithGatewayConfig(SaltBootUpdateConfiguration saltBootUpdateConfiguration, GatewayConfig gatewayConfig) { + try { + hostOrchestrator.uploadFile( + gatewayConfig, + saltBootUpdateConfiguration.targetPrivateIps(), + saltBootUpdateConfiguration.exitCriteriaModel(), + "/tmp", + "saltboottest-" + System.currentTimeMillis(), + "test".getBytes(StandardCharsets.UTF_8)); + LOGGER.info("Salt boot is reachable with gateway config."); + return true; + } catch (CloudbreakOrchestratorFailedException e) { + LOGGER.info("Salt boot is not reachable with gateway config.", e); + return false; + } + } + + private void uploadFile(SaltBootUpdateConfiguration saltBootUpdateConfiguration, GatewayConfig gatewayConfig, String fileContent) { + try { + hostOrchestrator.uploadFile( + gatewayConfig, + saltBootUpdateConfiguration.targetPrivateIps(), + saltBootUpdateConfiguration.exitCriteriaModel(), + saltBootUpdateConfiguration.configFolder(), + saltBootUpdateConfiguration.configFile(), + fileContent.getBytes(StandardCharsets.UTF_8)); + LOGGER.info("Uploaded service configuration to {}/{} on hosts {}", + saltBootUpdateConfiguration.configFolder(), saltBootUpdateConfiguration.configFile(), saltBootUpdateConfiguration.targetPrivateIps()); + } catch (CloudbreakOrchestratorFailedException e) { + LOGGER.error("Couldn't upload service configuration to {}/{} on hosts {}", + saltBootUpdateConfiguration.configFolder(), saltBootUpdateConfiguration.configFile(), saltBootUpdateConfiguration.targetPrivateIps(), + e); + throw new SecretRotationException(e, getType()); + } + } + + private void restartSaltBootService(SaltBootUpdateConfiguration serviceConfig, GatewayConfig gatewayConfig) { + if (CollectionUtils.isNotEmpty(serviceConfig.serviceRestartActions())) { + try { + LOGGER.info("Executing restart actions {} on hosts {}", serviceConfig.serviceRestartActions(), serviceConfig.targetFqdns()); + hostOrchestrator.executeSaltState( + gatewayConfig, + serviceConfig.targetFqdns(), + serviceConfig.serviceRestartActions(), + serviceConfig.exitCriteriaModel(), + Optional.of(serviceConfig.maxRetryCount()), + Optional.of(serviceConfig.maxRetryCount())); + } catch (CloudbreakOrchestratorFailedException e) { + throw new SecretRotationException(e, getType()); + } + } + } + + private GatewayConfig withOldSecrets(GatewayConfig gatewayConfig, SaltBootUpdateConfiguration saltBootUpdateConfiguration) { + return changeGatewayConfig(gatewayConfig, saltBootUpdateConfiguration.oldSaltBootPassword(), saltBootUpdateConfiguration.oldSaltBootPrivateKey()); + } + + private GatewayConfig withNewSecrets(GatewayConfig gatewayConfig, SaltBootUpdateConfiguration saltBootUpdateConfiguration) { + return changeGatewayConfig(gatewayConfig, saltBootUpdateConfiguration.newSaltBootPassword(), saltBootUpdateConfiguration.newSaltBootPrivateKey()); + } + + private GatewayConfig changeGatewayConfig(GatewayConfig gatewayConfig, String saltBootPassword, String saltBootPrivateKey) { + return gatewayConfig.toBuilder() + .withSaltBootPassword(saltBootPassword) + .withSignatureKey(new String(BASE64.decode(saltBootPrivateKey))) + .build(); + } +} diff --git a/core/src/main/java/com/sequenceiq/cloudbreak/rotation/executor/SaltPillarRotationExecutor.java b/core/src/main/java/com/sequenceiq/cloudbreak/rotation/executor/SaltPillarRotationExecutor.java index f1fcdebd6e5..016f1fa9c52 100644 --- a/core/src/main/java/com/sequenceiq/cloudbreak/rotation/executor/SaltPillarRotationExecutor.java +++ b/core/src/main/java/com/sequenceiq/cloudbreak/rotation/executor/SaltPillarRotationExecutor.java @@ -16,9 +16,8 @@ import com.sequenceiq.cloudbreak.orchestrator.model.SaltPillarProperties; import com.sequenceiq.cloudbreak.rotation.CloudbreakSecretRotationStep; import com.sequenceiq.cloudbreak.rotation.ExitCriteriaProvider; +import com.sequenceiq.cloudbreak.rotation.SecretRotationStep; import com.sequenceiq.cloudbreak.rotation.context.SaltPillarRotationContext; -import com.sequenceiq.cloudbreak.rotation.secret.AbstractRotationExecutor; -import com.sequenceiq.cloudbreak.rotation.secret.step.SecretRotationStep; import com.sequenceiq.cloudbreak.service.salt.SaltStateParamsService; import com.sequenceiq.cloudbreak.service.stack.StackDtoService; diff --git a/core/src/main/java/com/sequenceiq/cloudbreak/rotation/executor/SaltRunOrchestratorStateRotationExecutor.java b/core/src/main/java/com/sequenceiq/cloudbreak/rotation/executor/SaltRunOrchestratorStateRotationExecutor.java index 3be451d7cc4..13ccac17c42 100644 --- a/core/src/main/java/com/sequenceiq/cloudbreak/rotation/executor/SaltRunOrchestratorStateRotationExecutor.java +++ b/core/src/main/java/com/sequenceiq/cloudbreak/rotation/executor/SaltRunOrchestratorStateRotationExecutor.java @@ -11,9 +11,8 @@ import com.sequenceiq.cloudbreak.orchestrator.host.HostOrchestrator; import com.sequenceiq.cloudbreak.orchestrator.host.OrchestratorStateParams; import com.sequenceiq.cloudbreak.rotation.CloudbreakSecretRotationStep; +import com.sequenceiq.cloudbreak.rotation.SecretRotationStep; import com.sequenceiq.cloudbreak.rotation.context.SaltRunOrchestratorStateRotationContext; -import com.sequenceiq.cloudbreak.rotation.secret.AbstractRotationExecutor; -import com.sequenceiq.cloudbreak.rotation.secret.step.SecretRotationStep; @Component public class SaltRunOrchestratorStateRotationExecutor extends AbstractRotationExecutor { diff --git a/core/src/main/java/com/sequenceiq/cloudbreak/rotation/executor/SaltStateApplyRotationExecutor.java b/core/src/main/java/com/sequenceiq/cloudbreak/rotation/executor/SaltStateApplyRotationExecutor.java index beacfebcd0f..528c9fb4fd1 100644 --- a/core/src/main/java/com/sequenceiq/cloudbreak/rotation/executor/SaltStateApplyRotationExecutor.java +++ b/core/src/main/java/com/sequenceiq/cloudbreak/rotation/executor/SaltStateApplyRotationExecutor.java @@ -14,9 +14,8 @@ import com.google.common.base.Joiner; import com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException; import com.sequenceiq.cloudbreak.orchestrator.host.HostOrchestrator; +import com.sequenceiq.cloudbreak.rotation.SecretRotationStep; import com.sequenceiq.cloudbreak.rotation.context.SaltStateApplyRotationContext; -import com.sequenceiq.cloudbreak.rotation.secret.AbstractRotationExecutor; -import com.sequenceiq.cloudbreak.rotation.secret.step.SecretRotationStep; @Component public class SaltStateApplyRotationExecutor extends AbstractRotationExecutor { diff --git a/core/src/main/java/com/sequenceiq/cloudbreak/rotation/executor/UserDataRotationExecutor.java b/core/src/main/java/com/sequenceiq/cloudbreak/rotation/executor/UserDataRotationExecutor.java index 521c42c4d47..45b7804e0bd 100644 --- a/core/src/main/java/com/sequenceiq/cloudbreak/rotation/executor/UserDataRotationExecutor.java +++ b/core/src/main/java/com/sequenceiq/cloudbreak/rotation/executor/UserDataRotationExecutor.java @@ -3,7 +3,7 @@ import static com.sequenceiq.cloudbreak.cloud.model.AvailabilityZone.availabilityZone; import static com.sequenceiq.cloudbreak.cloud.model.Location.location; import static com.sequenceiq.cloudbreak.cloud.model.Region.region; -import static com.sequenceiq.cloudbreak.rotation.secret.step.CommonSecretRotationStep.USER_DATA; +import static com.sequenceiq.cloudbreak.rotation.CommonSecretRotationStep.USER_DATA; import java.util.List; import java.util.Map; @@ -26,13 +26,12 @@ import com.sequenceiq.cloudbreak.cloud.model.CloudCredential; import com.sequenceiq.cloudbreak.cloud.model.CloudResource; import com.sequenceiq.cloudbreak.cloud.model.CloudStack; -import com.sequenceiq.cloudbreak.cloud.rotation.UserDataRotationContext; import com.sequenceiq.cloudbreak.converter.spi.ResourceToCloudResourceConverter; import com.sequenceiq.cloudbreak.converter.spi.StackToCloudStackConverter; import com.sequenceiq.cloudbreak.dto.StackDto; -import com.sequenceiq.cloudbreak.rotation.secret.AbstractRotationExecutor; -import com.sequenceiq.cloudbreak.rotation.secret.SecretRotationException; -import com.sequenceiq.cloudbreak.rotation.secret.step.SecretRotationStep; +import com.sequenceiq.cloudbreak.rotation.SecretRotationStep; +import com.sequenceiq.cloudbreak.rotation.common.SecretRotationException; +import com.sequenceiq.cloudbreak.rotation.secret.userdata.UserDataRotationContext; import com.sequenceiq.cloudbreak.rotation.secret.userdata.UserDataSecretModifier; import com.sequenceiq.cloudbreak.service.image.userdata.UserDataService; import com.sequenceiq.cloudbreak.service.resource.ResourceService; diff --git a/core/src/main/java/com/sequenceiq/cloudbreak/service/StackSecretRotationStatusService.java b/core/src/main/java/com/sequenceiq/cloudbreak/service/StackSecretRotationStatusService.java index ea65ceaa47c..6d8b9e87e16 100644 --- a/core/src/main/java/com/sequenceiq/cloudbreak/service/StackSecretRotationStatusService.java +++ b/core/src/main/java/com/sequenceiq/cloudbreak/service/StackSecretRotationStatusService.java @@ -6,9 +6,9 @@ import org.springframework.stereotype.Component; import com.sequenceiq.cloudbreak.api.endpoint.v4.common.DetailedStackStatus; +import com.sequenceiq.cloudbreak.rotation.service.status.SecretRotationStatusService; import com.sequenceiq.cloudbreak.service.stack.StackDtoService; import com.sequenceiq.cloudbreak.view.StackView; -import com.sequenceiq.flow.rotation.status.service.SecretRotationStatusService; @Primary @Component diff --git a/core/src/main/java/com/sequenceiq/cloudbreak/service/stack/flow/StackOperationService.java b/core/src/main/java/com/sequenceiq/cloudbreak/service/stack/flow/StackOperationService.java index fbc69ec1ed1..1350ad8e37c 100644 --- a/core/src/main/java/com/sequenceiq/cloudbreak/service/stack/flow/StackOperationService.java +++ b/core/src/main/java/com/sequenceiq/cloudbreak/service/stack/flow/StackOperationService.java @@ -52,8 +52,9 @@ import com.sequenceiq.cloudbreak.dto.StackDto; import com.sequenceiq.cloudbreak.logger.MDCBuilder; import com.sequenceiq.cloudbreak.rotation.CloudbreakSecretType; -import com.sequenceiq.cloudbreak.rotation.secret.RotationFlowExecutionType; -import com.sequenceiq.cloudbreak.rotation.secret.SecretType; +import com.sequenceiq.cloudbreak.rotation.RotationFlowExecutionType; +import com.sequenceiq.cloudbreak.rotation.SecretType; +import com.sequenceiq.cloudbreak.rotation.service.SecretRotationValidator; import com.sequenceiq.cloudbreak.service.StackUpdater; import com.sequenceiq.cloudbreak.service.cluster.ClusterService; import com.sequenceiq.cloudbreak.service.cluster.flow.ClusterOperationService; @@ -75,7 +76,6 @@ import com.sequenceiq.cloudbreak.view.StackView; import com.sequenceiq.environment.api.v1.environment.model.response.EnvironmentStatus; import com.sequenceiq.flow.api.model.FlowIdentifier; -import com.sequenceiq.flow.rotation.service.SecretRotationValidator; @Service public class StackOperationService { diff --git a/core/src/test/java/com/sequenceiq/cloudbreak/JpaTest.java b/core/src/test/java/com/sequenceiq/cloudbreak/JpaTest.java index 5d2599adbbd..9d73ef32853 100644 --- a/core/src/test/java/com/sequenceiq/cloudbreak/JpaTest.java +++ b/core/src/test/java/com/sequenceiq/cloudbreak/JpaTest.java @@ -29,7 +29,7 @@ "com.sequenceiq.cloudbreak.workspace.repository", "com.sequenceiq.cloudbreak.workspace.model", "com.sequenceiq.flow.domain", - "com.sequenceiq.flow.rotation", + "com.sequenceiq.cloudbreak.rotation", "com.sequenceiq.cloudbreak.ha.domain", "com.sequenceiq.cloudbreak.structuredevent.repository", "com.sequenceiq.cloudbreak.structuredevent.domain" diff --git a/core/src/test/java/com/sequenceiq/cloudbreak/core/flow2/EnforceFlowFinalizer.java b/core/src/test/java/com/sequenceiq/cloudbreak/core/flow2/EnforceFlowFinalizer.java index 7cc0c78f2d3..f8d39c70e55 100644 --- a/core/src/test/java/com/sequenceiq/cloudbreak/core/flow2/EnforceFlowFinalizer.java +++ b/core/src/test/java/com/sequenceiq/cloudbreak/core/flow2/EnforceFlowFinalizer.java @@ -12,6 +12,8 @@ import org.reflections.scanners.SubTypesScanner; import com.google.common.base.Joiner; +import com.sequenceiq.cloudbreak.rotation.flow.rotation.config.SecretRotationFlowConfig; +import com.sequenceiq.cloudbreak.rotation.flow.status.SecretRotationStatusChangeFlowConfig; import com.sequenceiq.flow.core.config.FlowConfiguration; public class EnforceFlowFinalizer { @@ -19,10 +21,13 @@ public class EnforceFlowFinalizer { private static final Reflections REFLECTIONS = new Reflections("com.sequenceiq.cloudbreak", new SubTypesScanner(false)); + private static final Set EXCEPTIONS = Set.of(SecretRotationFlowConfig.class, SecretRotationStatusChangeFlowConfig.class); + @Test public void enforceStackStatusFlowFinalizer() { Set> flowConfigs = REFLECTIONS.getSubTypesOf(FlowConfiguration.class); Set flowConfigsWithoutFinalizer = flowConfigs.stream() + .filter(clazz -> !EXCEPTIONS.contains(clazz)) .filter(not(Class::isInterface)) .filter(not(Class::isAnonymousClass)) .filter(not(Class::isLocalClass)) diff --git a/core/src/test/java/com/sequenceiq/cloudbreak/core/flow2/externaldatabase/ExternalDatabaseServiceTest.java b/core/src/test/java/com/sequenceiq/cloudbreak/core/flow2/externaldatabase/ExternalDatabaseServiceTest.java index 5590161a8a6..d7ea1fcb7d2 100644 --- a/core/src/test/java/com/sequenceiq/cloudbreak/core/flow2/externaldatabase/ExternalDatabaseServiceTest.java +++ b/core/src/test/java/com/sequenceiq/cloudbreak/core/flow2/externaldatabase/ExternalDatabaseServiceTest.java @@ -1,6 +1,6 @@ package com.sequenceiq.cloudbreak.core.flow2.externaldatabase; -import static com.sequenceiq.cloudbreak.rotation.secret.RotationFlowExecutionType.ROTATE; +import static com.sequenceiq.cloudbreak.rotation.RotationFlowExecutionType.ROTATE; import static com.sequenceiq.redbeams.rotation.RedbeamsSecretType.REDBEAMS_EXTERNAL_DATABASE_ROOT_PASSWORD; import static java.util.Map.entry; import static org.assertj.core.api.Assertions.assertThat; @@ -53,7 +53,7 @@ import com.sequenceiq.cloudbreak.domain.stack.Stack; import com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster; import com.sequenceiq.cloudbreak.repository.cluster.ClusterRepository; -import com.sequenceiq.cloudbreak.rotation.secret.SecretRotationException; +import com.sequenceiq.cloudbreak.rotation.common.SecretRotationException; import com.sequenceiq.cloudbreak.service.externaldatabase.DatabaseOperation; import com.sequenceiq.cloudbreak.service.externaldatabase.DatabaseServerParameterDecorator; import com.sequenceiq.cloudbreak.service.externaldatabase.model.DatabaseServerParameter; diff --git a/core/src/test/java/com/sequenceiq/cloudbreak/rotation/context/provider/CMDBPasswordRotationContextProviderTest.java b/core/src/test/java/com/sequenceiq/cloudbreak/rotation/context/provider/CMDBPasswordRotationContextProviderTest.java index ebdb763b553..f52b9922099 100644 --- a/core/src/test/java/com/sequenceiq/cloudbreak/rotation/context/provider/CMDBPasswordRotationContextProviderTest.java +++ b/core/src/test/java/com/sequenceiq/cloudbreak/rotation/context/provider/CMDBPasswordRotationContextProviderTest.java @@ -30,8 +30,8 @@ import com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig; import com.sequenceiq.cloudbreak.rotation.CloudbreakSecretType; import com.sequenceiq.cloudbreak.rotation.ExitCriteriaProvider; -import com.sequenceiq.cloudbreak.rotation.secret.RotationContext; -import com.sequenceiq.cloudbreak.rotation.secret.step.SecretRotationStep; +import com.sequenceiq.cloudbreak.rotation.SecretRotationStep; +import com.sequenceiq.cloudbreak.rotation.common.RotationContext; import com.sequenceiq.cloudbreak.service.GatewayConfigService; import com.sequenceiq.cloudbreak.service.rdsconfig.RdsConfigService; import com.sequenceiq.cloudbreak.service.stack.StackDtoService; diff --git a/core/src/test/java/com/sequenceiq/cloudbreak/rotation/context/provider/CMServiceDBPasswordRotationContextProviderTest.java b/core/src/test/java/com/sequenceiq/cloudbreak/rotation/context/provider/CMServiceDBPasswordRotationContextProviderTest.java index 3eb5e9273e9..c02e2a0ce84 100644 --- a/core/src/test/java/com/sequenceiq/cloudbreak/rotation/context/provider/CMServiceDBPasswordRotationContextProviderTest.java +++ b/core/src/test/java/com/sequenceiq/cloudbreak/rotation/context/provider/CMServiceDBPasswordRotationContextProviderTest.java @@ -27,9 +27,9 @@ import com.sequenceiq.cloudbreak.dto.StackDto; import com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig; import com.sequenceiq.cloudbreak.rotation.ExitCriteriaProvider; +import com.sequenceiq.cloudbreak.rotation.SecretRotationStep; +import com.sequenceiq.cloudbreak.rotation.common.RotationContext; import com.sequenceiq.cloudbreak.rotation.context.CMServiceConfigRotationContext; -import com.sequenceiq.cloudbreak.rotation.secret.RotationContext; -import com.sequenceiq.cloudbreak.rotation.secret.step.SecretRotationStep; import com.sequenceiq.cloudbreak.service.GatewayConfigService; import com.sequenceiq.cloudbreak.service.rdsconfig.AbstractRdsConfigProvider; import com.sequenceiq.cloudbreak.service.rdsconfig.RdsConfigService; diff --git a/core/src/test/java/com/sequenceiq/cloudbreak/rotation/context/provider/CMUserRotationContextProviderTestUtils.java b/core/src/test/java/com/sequenceiq/cloudbreak/rotation/context/provider/CMUserRotationContextProviderTestUtils.java index 7f5d7407600..6cfa404be27 100644 --- a/core/src/test/java/com/sequenceiq/cloudbreak/rotation/context/provider/CMUserRotationContextProviderTestUtils.java +++ b/core/src/test/java/com/sequenceiq/cloudbreak/rotation/context/provider/CMUserRotationContextProviderTestUtils.java @@ -14,9 +14,9 @@ import com.sequenceiq.cloudbreak.domain.stack.Stack; import com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster; import com.sequenceiq.cloudbreak.dto.StackDto; -import com.sequenceiq.cloudbreak.rotation.secret.RotationContext; -import com.sequenceiq.cloudbreak.rotation.secret.SecretType; -import com.sequenceiq.cloudbreak.rotation.secret.step.SecretRotationStep; +import com.sequenceiq.cloudbreak.rotation.SecretRotationStep; +import com.sequenceiq.cloudbreak.rotation.SecretType; +import com.sequenceiq.cloudbreak.rotation.common.RotationContext; import com.sequenceiq.cloudbreak.service.secret.domain.Secret; import com.sequenceiq.cloudbreak.service.secret.vault.VaultSecret; import com.sequenceiq.cloudbreak.service.stack.StackDtoService; diff --git a/core/src/test/java/com/sequenceiq/cloudbreak/rotation/context/provider/DatahubExternalDatabaseRootPasswordRotationContextProviderTest.java b/core/src/test/java/com/sequenceiq/cloudbreak/rotation/context/provider/DatahubExternalDatabaseRootPasswordRotationContextProviderTest.java index 49aecb71309..901ebb80e21 100644 --- a/core/src/test/java/com/sequenceiq/cloudbreak/rotation/context/provider/DatahubExternalDatabaseRootPasswordRotationContextProviderTest.java +++ b/core/src/test/java/com/sequenceiq/cloudbreak/rotation/context/provider/DatahubExternalDatabaseRootPasswordRotationContextProviderTest.java @@ -12,12 +12,12 @@ import org.mockito.junit.jupiter.MockitoExtension; import com.sequenceiq.cloudbreak.rotation.CloudbreakSecretRotationStep; +import com.sequenceiq.cloudbreak.rotation.CommonSecretRotationStep; import com.sequenceiq.cloudbreak.rotation.DatabaseRootPasswordSaltPillarGenerator; +import com.sequenceiq.cloudbreak.rotation.SecretRotationStep; +import com.sequenceiq.cloudbreak.rotation.common.RotationContext; import com.sequenceiq.cloudbreak.rotation.context.SaltPillarRotationContext; -import com.sequenceiq.cloudbreak.rotation.secret.RotationContext; -import com.sequenceiq.cloudbreak.rotation.secret.context.PollerRotationContext; -import com.sequenceiq.cloudbreak.rotation.secret.step.CommonSecretRotationStep; -import com.sequenceiq.cloudbreak.rotation.secret.step.SecretRotationStep; +import com.sequenceiq.cloudbreak.rotation.secret.poller.PollerRotationContext; import com.sequenceiq.redbeams.rotation.RedbeamsSecretType; @ExtendWith(MockitoExtension.class) diff --git a/core/src/test/java/com/sequenceiq/cloudbreak/rotation/context/provider/DatalakeExternalDatabaseRootPasswordRotationContextProviderTest.java b/core/src/test/java/com/sequenceiq/cloudbreak/rotation/context/provider/DatalakeExternalDatabaseRootPasswordRotationContextProviderTest.java index bcfaf3abe80..f28ba1a895b 100644 --- a/core/src/test/java/com/sequenceiq/cloudbreak/rotation/context/provider/DatalakeExternalDatabaseRootPasswordRotationContextProviderTest.java +++ b/core/src/test/java/com/sequenceiq/cloudbreak/rotation/context/provider/DatalakeExternalDatabaseRootPasswordRotationContextProviderTest.java @@ -13,9 +13,9 @@ import com.sequenceiq.cloudbreak.rotation.CloudbreakSecretRotationStep; import com.sequenceiq.cloudbreak.rotation.DatabaseRootPasswordSaltPillarGenerator; +import com.sequenceiq.cloudbreak.rotation.SecretRotationStep; +import com.sequenceiq.cloudbreak.rotation.common.RotationContext; import com.sequenceiq.cloudbreak.rotation.context.SaltPillarRotationContext; -import com.sequenceiq.cloudbreak.rotation.secret.RotationContext; -import com.sequenceiq.cloudbreak.rotation.secret.step.SecretRotationStep; @ExtendWith(MockitoExtension.class) class DatalakeExternalDatabaseRootPasswordRotationContextProviderTest { diff --git a/core/src/test/java/com/sequenceiq/cloudbreak/rotation/saltboot/SaltBootRotationContextProviderTest.java b/core/src/test/java/com/sequenceiq/cloudbreak/rotation/context/provider/SaltBootRotationContextProviderTest.java similarity index 80% rename from core/src/test/java/com/sequenceiq/cloudbreak/rotation/saltboot/SaltBootRotationContextProviderTest.java rename to core/src/test/java/com/sequenceiq/cloudbreak/rotation/context/provider/SaltBootRotationContextProviderTest.java index 86607c75bea..e6429a308f0 100644 --- a/core/src/test/java/com/sequenceiq/cloudbreak/rotation/saltboot/SaltBootRotationContextProviderTest.java +++ b/core/src/test/java/com/sequenceiq/cloudbreak/rotation/context/provider/SaltBootRotationContextProviderTest.java @@ -1,4 +1,4 @@ -package com.sequenceiq.cloudbreak.rotation.saltboot; +package com.sequenceiq.cloudbreak.rotation.context.provider; import static org.junit.jupiter.api.Assertions.assertInstanceOf; import static org.mockito.ArgumentMatchers.anyString; @@ -13,15 +13,15 @@ import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; -import com.sequenceiq.cloudbreak.cloud.rotation.UserDataRotationContext; import com.sequenceiq.cloudbreak.domain.SaltSecurityConfig; import com.sequenceiq.cloudbreak.domain.SecurityConfig; import com.sequenceiq.cloudbreak.dto.StackDto; -import com.sequenceiq.cloudbreak.orchestrator.rotation.ServiceConfigRotationContext; -import com.sequenceiq.cloudbreak.rotation.secret.RotationContext; -import com.sequenceiq.cloudbreak.rotation.secret.context.CustomJobRotationContext; -import com.sequenceiq.cloudbreak.rotation.secret.step.CommonSecretRotationStep; -import com.sequenceiq.cloudbreak.rotation.secret.step.SecretRotationStep; +import com.sequenceiq.cloudbreak.rotation.CommonSecretRotationStep; +import com.sequenceiq.cloudbreak.rotation.SecretRotationStep; +import com.sequenceiq.cloudbreak.rotation.common.RotationContext; +import com.sequenceiq.cloudbreak.rotation.context.saltboot.SaltBootConfigRotationContext; +import com.sequenceiq.cloudbreak.rotation.secret.custom.CustomJobRotationContext; +import com.sequenceiq.cloudbreak.rotation.secret.userdata.UserDataRotationContext; import com.sequenceiq.cloudbreak.rotation.secret.vault.VaultRotationContext; import com.sequenceiq.cloudbreak.service.secret.domain.Secret; import com.sequenceiq.cloudbreak.service.stack.StackDtoService; @@ -73,7 +73,7 @@ public void testSaltBootContextProviderProvidesAllContextData() { assertInstanceOf(VaultRotationContext.class, contexts.get(CommonSecretRotationStep.VAULT)); assertInstanceOf(CustomJobRotationContext.class, contexts.get(CommonSecretRotationStep.CUSTOM_JOB)); - assertInstanceOf(ServiceConfigRotationContext.class, contexts.get(CommonSecretRotationStep.SERVICE_CONFIG)); + assertInstanceOf(SaltBootConfigRotationContext.class, contexts.get(CommonSecretRotationStep.SALTBOOT_CONFIG)); assertInstanceOf(UserDataRotationContext.class, contexts.get(CommonSecretRotationStep.USER_DATA)); } } \ No newline at end of file diff --git a/core/src/test/java/com/sequenceiq/cloudbreak/rotation/context/provider/UserKeyPairRotationContextProviderTest.java b/core/src/test/java/com/sequenceiq/cloudbreak/rotation/context/provider/UserKeyPairRotationContextProviderTest.java index 351075cb12a..e1ae4abc645 100644 --- a/core/src/test/java/com/sequenceiq/cloudbreak/rotation/context/provider/UserKeyPairRotationContextProviderTest.java +++ b/core/src/test/java/com/sequenceiq/cloudbreak/rotation/context/provider/UserKeyPairRotationContextProviderTest.java @@ -24,8 +24,8 @@ import com.sequenceiq.cloudbreak.dto.StackDto; import com.sequenceiq.cloudbreak.repository.StackAuthenticationRepository; import com.sequenceiq.cloudbreak.rotation.CloudbreakSecretType; -import com.sequenceiq.cloudbreak.rotation.secret.RotationContext; -import com.sequenceiq.cloudbreak.rotation.secret.step.SecretRotationStep; +import com.sequenceiq.cloudbreak.rotation.SecretRotationStep; +import com.sequenceiq.cloudbreak.rotation.common.RotationContext; import com.sequenceiq.cloudbreak.service.environment.EnvironmentClientService; import com.sequenceiq.cloudbreak.service.stack.StackDtoService; import com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse; diff --git a/core/src/test/java/com/sequenceiq/cloudbreak/rotation/executor/CMServiceConfigRotationExecutorTest.java b/core/src/test/java/com/sequenceiq/cloudbreak/rotation/executor/CMServiceConfigRotationExecutorTest.java index 0e5cb6396f7..b894b80ac66 100644 --- a/core/src/test/java/com/sequenceiq/cloudbreak/rotation/executor/CMServiceConfigRotationExecutorTest.java +++ b/core/src/test/java/com/sequenceiq/cloudbreak/rotation/executor/CMServiceConfigRotationExecutorTest.java @@ -9,7 +9,6 @@ import java.util.Optional; -import org.apache.commons.lang3.reflect.FieldUtils; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -22,7 +21,7 @@ import com.sequenceiq.cloudbreak.cluster.api.ClusterModificationService; import com.sequenceiq.cloudbreak.dto.StackDto; import com.sequenceiq.cloudbreak.rotation.context.CMServiceConfigRotationContext; -import com.sequenceiq.cloudbreak.rotation.secret.SecretRotationProgressService; +import com.sequenceiq.cloudbreak.rotation.service.progress.SecretRotationStepProgressService; import com.sequenceiq.cloudbreak.service.cluster.ClusterApiConnectors; import com.sequenceiq.cloudbreak.service.secret.service.SecretService; import com.sequenceiq.cloudbreak.service.stack.StackDtoService; @@ -40,14 +39,13 @@ public class CMServiceConfigRotationExecutorTest { private StackDtoService stackService; @Mock - private SecretRotationProgressService secretRotationProgressService; + private SecretRotationStepProgressService secretRotationProgressService; @InjectMocks private CMServiceConfigRotationExecutor underTest; @BeforeEach - public void mockProgressService() throws IllegalAccessException { - FieldUtils.writeField(underTest, "secretRotationProgressService", Optional.of(secretRotationProgressService), true); + public void mockProgressService() { lenient().when(secretRotationProgressService.latestStep(any(), any(), any(), any())).thenReturn(Optional.empty()); } diff --git a/core/src/test/java/com/sequenceiq/cloudbreak/rotation/executor/CMUserRotationExecutorTest.java b/core/src/test/java/com/sequenceiq/cloudbreak/rotation/executor/CMUserRotationExecutorTest.java index 843d3359389..118f9688778 100644 --- a/core/src/test/java/com/sequenceiq/cloudbreak/rotation/executor/CMUserRotationExecutorTest.java +++ b/core/src/test/java/com/sequenceiq/cloudbreak/rotation/executor/CMUserRotationExecutorTest.java @@ -16,7 +16,6 @@ import java.util.Optional; -import org.apache.commons.lang3.reflect.FieldUtils; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -29,9 +28,9 @@ import com.sequenceiq.cloudbreak.cluster.api.ClusterSecurityService; import com.sequenceiq.cloudbreak.dto.StackDto; import com.sequenceiq.cloudbreak.dto.StackDtoDelegate; +import com.sequenceiq.cloudbreak.rotation.common.SecretRotationException; import com.sequenceiq.cloudbreak.rotation.context.CMUserRotationContext; -import com.sequenceiq.cloudbreak.rotation.secret.SecretRotationException; -import com.sequenceiq.cloudbreak.rotation.secret.SecretRotationProgressService; +import com.sequenceiq.cloudbreak.rotation.service.progress.SecretRotationStepProgressService; import com.sequenceiq.cloudbreak.service.CloudbreakException; import com.sequenceiq.cloudbreak.service.cluster.ClusterApiConnectors; import com.sequenceiq.cloudbreak.service.secret.domain.RotationSecret; @@ -57,14 +56,13 @@ public class CMUserRotationExecutorTest { private SecretService secretService; @Mock - private SecretRotationProgressService secretRotationProgressService; + private SecretRotationStepProgressService secretRotationProgressService; @InjectMocks private CMUserRotationExecutor underTest; @BeforeEach - public void mockProgressService() throws IllegalAccessException { - FieldUtils.writeField(underTest, "secretRotationProgressService", Optional.of(secretRotationProgressService), true); + public void mockProgressService() { lenient().when(secretRotationProgressService.latestStep(any(), any(), any(), any())).thenReturn(Optional.empty()); } diff --git a/core/src/test/java/com/sequenceiq/cloudbreak/rotation/executor/ClusterProxyRotationExecutorTest.java b/core/src/test/java/com/sequenceiq/cloudbreak/rotation/executor/ClusterProxyRotationExecutorTest.java index bccf5b71c84..204d8be479a 100644 --- a/core/src/test/java/com/sequenceiq/cloudbreak/rotation/executor/ClusterProxyRotationExecutorTest.java +++ b/core/src/test/java/com/sequenceiq/cloudbreak/rotation/executor/ClusterProxyRotationExecutorTest.java @@ -23,9 +23,9 @@ import com.sequenceiq.cloudbreak.core.flow2.cluster.provision.service.ClusterProxyService; import com.sequenceiq.cloudbreak.domain.stack.Stack; import com.sequenceiq.cloudbreak.dto.StackDto; +import com.sequenceiq.cloudbreak.rotation.common.SecretRotationException; import com.sequenceiq.cloudbreak.rotation.context.ClusterProxyRotationContext; -import com.sequenceiq.cloudbreak.rotation.secret.SecretRotationException; -import com.sequenceiq.cloudbreak.rotation.secret.SecretRotationProgressService; +import com.sequenceiq.cloudbreak.rotation.service.progress.SecretRotationStepProgressService; import com.sequenceiq.cloudbreak.service.stack.StackDtoService; @ExtendWith(MockitoExtension.class) @@ -38,14 +38,13 @@ public class ClusterProxyRotationExecutorTest { private ClusterProxyService clusterProxyService; @Mock - private SecretRotationProgressService secretRotationProgressService; + private SecretRotationStepProgressService secretRotationProgressService; @InjectMocks private ClusterProxyRotationExecutor underTest; @BeforeEach - public void mockProgressService() throws IllegalAccessException { - FieldUtils.writeField(underTest, "secretRotationProgressService", Optional.of(secretRotationProgressService), true); + public void mockProgressService() { lenient().when(secretRotationProgressService.latestStep(any(), any(), any(), any())).thenReturn(Optional.empty()); } diff --git a/core/src/test/java/com/sequenceiq/cloudbreak/rotation/executor/RedbeamsPollerRotationExecutorTest.java b/core/src/test/java/com/sequenceiq/cloudbreak/rotation/executor/RedbeamsPollerRotationExecutorTest.java index 05757855971..fe7a7e507d2 100644 --- a/core/src/test/java/com/sequenceiq/cloudbreak/rotation/executor/RedbeamsPollerRotationExecutorTest.java +++ b/core/src/test/java/com/sequenceiq/cloudbreak/rotation/executor/RedbeamsPollerRotationExecutorTest.java @@ -13,7 +13,6 @@ import java.util.Optional; -import org.apache.commons.lang3.reflect.FieldUtils; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -26,10 +25,10 @@ import com.sequenceiq.cloudbreak.core.flow2.externaldatabase.ExternalDatabaseService; import com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster; import com.sequenceiq.cloudbreak.dto.StackDto; -import com.sequenceiq.cloudbreak.rotation.secret.RotationFlowExecutionType; -import com.sequenceiq.cloudbreak.rotation.secret.SecretRotationException; -import com.sequenceiq.cloudbreak.rotation.secret.SecretRotationProgressService; -import com.sequenceiq.cloudbreak.rotation.secret.context.PollerRotationContext; +import com.sequenceiq.cloudbreak.rotation.RotationFlowExecutionType; +import com.sequenceiq.cloudbreak.rotation.common.SecretRotationException; +import com.sequenceiq.cloudbreak.rotation.secret.poller.PollerRotationContext; +import com.sequenceiq.cloudbreak.rotation.service.progress.SecretRotationStepProgressService; import com.sequenceiq.cloudbreak.service.stack.StackDtoService; @ExtendWith(MockitoExtension.class) @@ -46,14 +45,13 @@ class RedbeamsPollerRotationExecutorTest { private StackDtoService stackDtoService; @Mock - private SecretRotationProgressService secretRotationProgressService; + private SecretRotationStepProgressService secretRotationProgressService; @InjectMocks private RedbeamsPollerRotationExecutor underTest; @BeforeEach - public void mockProgressService() throws IllegalAccessException { - FieldUtils.writeField(underTest, "secretRotationProgressService", Optional.of(secretRotationProgressService), true); + public void mockProgressService() { lenient().when(secretRotationProgressService.latestStep(any(), any(), any(), any())).thenReturn(Optional.empty()); } diff --git a/orchestrator-api/src/test/java/com/sequenceiq/cloudbreak/orchestrator/rotation/ServiceConfigRotationExecutorTest.java b/core/src/test/java/com/sequenceiq/cloudbreak/rotation/executor/SaltBootConfigRotationExecutorTest.java similarity index 84% rename from orchestrator-api/src/test/java/com/sequenceiq/cloudbreak/orchestrator/rotation/ServiceConfigRotationExecutorTest.java rename to core/src/test/java/com/sequenceiq/cloudbreak/rotation/executor/SaltBootConfigRotationExecutorTest.java index aaddf5f5072..fd99e8a656c 100644 --- a/orchestrator-api/src/test/java/com/sequenceiq/cloudbreak/orchestrator/rotation/ServiceConfigRotationExecutorTest.java +++ b/core/src/test/java/com/sequenceiq/cloudbreak/rotation/executor/SaltBootConfigRotationExecutorTest.java @@ -1,4 +1,4 @@ -package com.sequenceiq.cloudbreak.orchestrator.rotation; +package com.sequenceiq.cloudbreak.rotation.executor; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; @@ -16,7 +16,6 @@ import java.util.Optional; import java.util.Set; -import org.apache.commons.lang3.reflect.FieldUtils; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -32,11 +31,13 @@ import com.sequenceiq.cloudbreak.orchestrator.host.HostOrchestrator; import com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig; import com.sequenceiq.cloudbreak.orchestrator.state.ExitCriteriaModel; -import com.sequenceiq.cloudbreak.rotation.secret.SecretRotationException; -import com.sequenceiq.cloudbreak.rotation.secret.SecretRotationProgressService; +import com.sequenceiq.cloudbreak.rotation.common.SecretRotationException; +import com.sequenceiq.cloudbreak.rotation.context.saltboot.SaltBootConfigRotationContext; +import com.sequenceiq.cloudbreak.rotation.context.saltboot.SaltBootUpdateConfiguration; +import com.sequenceiq.cloudbreak.rotation.service.progress.SecretRotationStepProgressService; @ExtendWith(MockitoExtension.class) -class ServiceConfigRotationExecutorTest { +class SaltBootConfigRotationExecutorTest { private static final String RESOURCE_CRN = "resourceCrn"; @@ -60,10 +61,10 @@ class ServiceConfigRotationExecutorTest { private HostOrchestrator hostOrchestrator; @Mock - private SecretRotationProgressService secretRotationProgressService; + private SecretRotationStepProgressService secretRotationProgressService; @InjectMocks - private ServiceConfigRotationExecutor underTest; + private SaltBootConfigRotationExecutor underTest; @Captor private ArgumentCaptor gatewayConfigCaptor; @@ -71,14 +72,13 @@ class ServiceConfigRotationExecutorTest { private GatewayConfig gatewayConfig = GatewayConfig.builder().build(); @BeforeEach - public void setUp() throws IllegalAccessException { - FieldUtils.writeField(underTest, "secretRotationProgressService", Optional.of(secretRotationProgressService), true); + public void setUp() { lenient().when(secretRotationProgressService.latestStep(any(), any(), any(), any())).thenReturn(Optional.empty()); } @Test public void rotateWithOldSaltBootSecrets() throws Exception { - ServiceConfigRotationContext context = getServiceConfigRotationContext(); + SaltBootConfigRotationContext context = getServiceConfigRotationContext(); underTest.rotate(context); @@ -91,7 +91,7 @@ public void rotateWithOldSaltBootSecrets() throws Exception { @Test public void rotateWithNewSaltBootSecrets() throws Exception { givenSaltBootTestFailsFirstThenCompletes(); - ServiceConfigRotationContext context = getServiceConfigRotationContext(); + SaltBootConfigRotationContext context = getServiceConfigRotationContext(); underTest.rotate(context); @@ -104,7 +104,7 @@ public void rotateWithNewSaltBootSecrets() throws Exception { @Test public void rotateFailsWhenSaltBootIsNotReachable() throws Exception { givenSaltBootTestFails(); - ServiceConfigRotationContext context = getServiceConfigRotationContext(); + SaltBootConfigRotationContext context = getServiceConfigRotationContext(); SecretRotationException exception = assertThrows(SecretRotationException.class, () -> underTest.rotate(context)); @@ -113,7 +113,7 @@ public void rotateFailsWhenSaltBootIsNotReachable() throws Exception { @Test public void rollbackWithOldSaltBootSecrets() throws Exception { - ServiceConfigRotationContext context = getServiceConfigRotationContext(); + SaltBootConfigRotationContext context = getServiceConfigRotationContext(); underTest.rollback(context); @@ -126,7 +126,7 @@ public void rollbackWithOldSaltBootSecrets() throws Exception { @Test public void rollbackWithNewSaltBootSecrets() throws Exception { givenSaltBootTestFailsFirstThenCompletes(); - ServiceConfigRotationContext context = getServiceConfigRotationContext(); + SaltBootConfigRotationContext context = getServiceConfigRotationContext(); underTest.rollback(context); @@ -139,7 +139,7 @@ public void rollbackWithNewSaltBootSecrets() throws Exception { @Test public void rollbackFailsWhenSaltBootIsNotReachable() throws Exception { givenSaltBootTestFails(); - ServiceConfigRotationContext context = getServiceConfigRotationContext(); + SaltBootConfigRotationContext context = getServiceConfigRotationContext(); SecretRotationException exception = assertThrows(SecretRotationException.class, () -> underTest.rollback(context)); @@ -192,11 +192,11 @@ private void assertGateWayConfig(GatewayConfig gatewayConfig, String expectedPas assertEquals(new String(BaseEncoding.base64().decode(expectedSigningKey)), gatewayConfig.getSignatureKey()); } - private ServiceConfigRotationContext getServiceConfigRotationContext() { - return new ServiceConfigRotationContext(RESOURCE_CRN) { + private SaltBootConfigRotationContext getServiceConfigRotationContext() { + return new SaltBootConfigRotationContext(RESOURCE_CRN) { @Override - public ServiceUpdateConfiguration getServiceUpdateConfiguration() { - return new ServiceUpdateConfiguration( + public SaltBootUpdateConfiguration getServiceUpdateConfiguration() { + return new SaltBootUpdateConfiguration( gatewayConfig, OLD_PASSWORD, NEW_PASSWORD, diff --git a/core/src/test/java/com/sequenceiq/cloudbreak/rotation/executor/SaltPillarRotationExecutorTest.java b/core/src/test/java/com/sequenceiq/cloudbreak/rotation/executor/SaltPillarRotationExecutorTest.java index 112b8792962..dae27bc5206 100644 --- a/core/src/test/java/com/sequenceiq/cloudbreak/rotation/executor/SaltPillarRotationExecutorTest.java +++ b/core/src/test/java/com/sequenceiq/cloudbreak/rotation/executor/SaltPillarRotationExecutorTest.java @@ -19,7 +19,6 @@ import java.util.Optional; import java.util.function.Function; -import org.apache.commons.lang3.reflect.FieldUtils; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -36,9 +35,9 @@ import com.sequenceiq.cloudbreak.orchestrator.host.HostOrchestrator; import com.sequenceiq.cloudbreak.orchestrator.host.OrchestratorStateParams; import com.sequenceiq.cloudbreak.rotation.ExitCriteriaProvider; +import com.sequenceiq.cloudbreak.rotation.common.SecretRotationException; import com.sequenceiq.cloudbreak.rotation.context.SaltPillarRotationContext; -import com.sequenceiq.cloudbreak.rotation.secret.SecretRotationException; -import com.sequenceiq.cloudbreak.rotation.secret.SecretRotationProgressService; +import com.sequenceiq.cloudbreak.rotation.service.progress.SecretRotationStepProgressService; import com.sequenceiq.cloudbreak.service.salt.SaltStateParamsService; import com.sequenceiq.cloudbreak.service.stack.StackDtoService; @@ -62,15 +61,14 @@ class SaltPillarRotationExecutorTest { private ExitCriteriaProvider exitCriteriaProvider; @Mock - private SecretRotationProgressService secretRotationProgressService; + private SecretRotationStepProgressService secretRotationProgressService; @InjectMocks private SaltPillarRotationExecutor underTest; @BeforeEach - void setup() throws IllegalAccessException { + void setup() { lenient().when(exitCriteriaProvider.get(any())).thenReturn(ClusterDeletionBasedExitCriteriaModel.nonCancellableModel()); - FieldUtils.writeField(underTest, "secretRotationProgressService", Optional.of(secretRotationProgressService), true); lenient().when(secretRotationProgressService.latestStep(any(), any(), any(), any())).thenReturn(Optional.empty()); } diff --git a/core/src/test/java/com/sequenceiq/cloudbreak/rotation/executor/SaltRunOrchestratorStateRotationExecutorTest.java b/core/src/test/java/com/sequenceiq/cloudbreak/rotation/executor/SaltRunOrchestratorStateRotationExecutorTest.java index 9f5f637266c..39f451e1f8d 100644 --- a/core/src/test/java/com/sequenceiq/cloudbreak/rotation/executor/SaltRunOrchestratorStateRotationExecutorTest.java +++ b/core/src/test/java/com/sequenceiq/cloudbreak/rotation/executor/SaltRunOrchestratorStateRotationExecutorTest.java @@ -14,7 +14,6 @@ import java.util.Map; import java.util.Optional; -import org.apache.commons.lang3.reflect.FieldUtils; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -27,10 +26,10 @@ import com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException; import com.sequenceiq.cloudbreak.orchestrator.host.HostOrchestrator; import com.sequenceiq.cloudbreak.orchestrator.host.OrchestratorStateParams; +import com.sequenceiq.cloudbreak.rotation.common.SecretRotationException; import com.sequenceiq.cloudbreak.rotation.context.SaltRunOrchestratorStateRotationContext; import com.sequenceiq.cloudbreak.rotation.context.SaltRunOrchestratorStateRotationContext.SaltRunOrchestratorStateRotationContextBuilder; -import com.sequenceiq.cloudbreak.rotation.secret.SecretRotationException; -import com.sequenceiq.cloudbreak.rotation.secret.SecretRotationProgressService; +import com.sequenceiq.cloudbreak.rotation.service.progress.SecretRotationStepProgressService; @ExtendWith(MockitoExtension.class) class SaltRunOrchestratorStateRotationExecutorTest { @@ -38,7 +37,7 @@ class SaltRunOrchestratorStateRotationExecutorTest { private HostOrchestrator hostOrchestrator; @Mock - private SecretRotationProgressService secretRotationProgressService; + private SecretRotationStepProgressService secretRotationProgressService; @InjectMocks private SaltRunOrchestratorStateRotationExecutor underTest; @@ -47,8 +46,7 @@ class SaltRunOrchestratorStateRotationExecutorTest { private ArgumentCaptor orchestratorStateParamsArgumentCaptor; @BeforeEach - public void mockProgressService() throws IllegalAccessException { - FieldUtils.writeField(underTest, "secretRotationProgressService", Optional.of(secretRotationProgressService), true); + public void mockProgressService() { lenient().when(secretRotationProgressService.latestStep(any(), any(), any(), any())).thenReturn(Optional.empty()); } diff --git a/core/src/test/java/com/sequenceiq/cloudbreak/rotation/executor/SaltStateApplyRotationExecutorTest.java b/core/src/test/java/com/sequenceiq/cloudbreak/rotation/executor/SaltStateApplyRotationExecutorTest.java index df03276cd2a..4bc33d7e4b8 100644 --- a/core/src/test/java/com/sequenceiq/cloudbreak/rotation/executor/SaltStateApplyRotationExecutorTest.java +++ b/core/src/test/java/com/sequenceiq/cloudbreak/rotation/executor/SaltStateApplyRotationExecutorTest.java @@ -13,7 +13,6 @@ import java.util.List; import java.util.Optional; -import org.apache.commons.lang3.reflect.FieldUtils; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -23,10 +22,10 @@ import com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException; import com.sequenceiq.cloudbreak.orchestrator.host.HostOrchestrator; +import com.sequenceiq.cloudbreak.rotation.common.SecretRotationException; import com.sequenceiq.cloudbreak.rotation.context.SaltStateApplyRotationContext; import com.sequenceiq.cloudbreak.rotation.context.SaltStateApplyRotationContext.SaltStateApplyRotationContextBuilder; -import com.sequenceiq.cloudbreak.rotation.secret.SecretRotationException; -import com.sequenceiq.cloudbreak.rotation.secret.SecretRotationProgressService; +import com.sequenceiq.cloudbreak.rotation.service.progress.SecretRotationStepProgressService; @ExtendWith(MockitoExtension.class) public class SaltStateApplyRotationExecutorTest { @@ -35,14 +34,13 @@ public class SaltStateApplyRotationExecutorTest { private HostOrchestrator hostOrchestrator; @Mock - private SecretRotationProgressService secretRotationProgressService; + private SecretRotationStepProgressService secretRotationProgressService; @InjectMocks private SaltStateApplyRotationExecutor underTest; @BeforeEach - public void mockProgressService() throws IllegalAccessException { - FieldUtils.writeField(underTest, "secretRotationProgressService", Optional.of(secretRotationProgressService), true); + public void mockProgressService() { lenient().when(secretRotationProgressService.latestStep(any(), any(), any(), any())).thenReturn(Optional.empty()); } diff --git a/core/src/test/java/com/sequenceiq/cloudbreak/rotation/saltboot/UserDataRotationExecutorTest.java b/core/src/test/java/com/sequenceiq/cloudbreak/rotation/executor/UserDataRotationExecutorTest.java similarity index 94% rename from core/src/test/java/com/sequenceiq/cloudbreak/rotation/saltboot/UserDataRotationExecutorTest.java rename to core/src/test/java/com/sequenceiq/cloudbreak/rotation/executor/UserDataRotationExecutorTest.java index 9db547e1218..9480760ea79 100644 --- a/core/src/test/java/com/sequenceiq/cloudbreak/rotation/saltboot/UserDataRotationExecutorTest.java +++ b/core/src/test/java/com/sequenceiq/cloudbreak/rotation/executor/UserDataRotationExecutorTest.java @@ -1,4 +1,4 @@ -package com.sequenceiq.cloudbreak.rotation.saltboot; +package com.sequenceiq.cloudbreak.rotation.executor; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; @@ -16,7 +16,6 @@ import java.util.Map; import java.util.Optional; -import org.apache.commons.lang3.reflect.FieldUtils; import org.apache.commons.lang3.tuple.Pair; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -35,16 +34,15 @@ import com.sequenceiq.cloudbreak.cloud.model.CloudCredential; import com.sequenceiq.cloudbreak.cloud.model.CloudResource; import com.sequenceiq.cloudbreak.cloud.model.CloudStack; -import com.sequenceiq.cloudbreak.cloud.rotation.UserDataRotationContext; import com.sequenceiq.cloudbreak.converter.spi.ResourceToCloudResourceConverter; import com.sequenceiq.cloudbreak.converter.spi.StackToCloudStackConverter; import com.sequenceiq.cloudbreak.domain.Resource; import com.sequenceiq.cloudbreak.dto.StackDto; -import com.sequenceiq.cloudbreak.rotation.executor.UserDataRotationExecutor; -import com.sequenceiq.cloudbreak.rotation.secret.SecretRotationException; -import com.sequenceiq.cloudbreak.rotation.secret.SecretRotationProgressService; -import com.sequenceiq.cloudbreak.rotation.secret.step.CommonSecretRotationStep; +import com.sequenceiq.cloudbreak.rotation.CommonSecretRotationStep; +import com.sequenceiq.cloudbreak.rotation.common.SecretRotationException; +import com.sequenceiq.cloudbreak.rotation.secret.userdata.UserDataRotationContext; import com.sequenceiq.cloudbreak.rotation.secret.userdata.UserDataSecretModifier; +import com.sequenceiq.cloudbreak.rotation.service.progress.SecretRotationStepProgressService; import com.sequenceiq.cloudbreak.service.image.userdata.UserDataService; import com.sequenceiq.cloudbreak.service.resource.ResourceService; import com.sequenceiq.cloudbreak.service.secret.domain.RotationSecret; @@ -130,12 +128,11 @@ class UserDataRotationExecutorTest { private CloudStack cloudStack; @Mock - private SecretRotationProgressService secretRotationProgressService; + private SecretRotationStepProgressService secretRotationProgressService; @BeforeEach public void setUp() throws IllegalAccessException { lenient().when(cloudStackConverter.convert(any())).thenReturn(cloudStack); - FieldUtils.writeField(underTest, "secretRotationProgressService", Optional.of(secretRotationProgressService), true); lenient().when(secretRotationProgressService.latestStep(any(), any(), any(), any())).thenReturn(Optional.empty()); } diff --git a/core/src/test/java/com/sequenceiq/cloudbreak/service/stack/flow/StackOperationServiceTest.java b/core/src/test/java/com/sequenceiq/cloudbreak/service/stack/flow/StackOperationServiceTest.java index 043e89d5019..1d3c92f0063 100644 --- a/core/src/test/java/com/sequenceiq/cloudbreak/service/stack/flow/StackOperationServiceTest.java +++ b/core/src/test/java/com/sequenceiq/cloudbreak/service/stack/flow/StackOperationServiceTest.java @@ -69,6 +69,7 @@ import com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup; import com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData; import com.sequenceiq.cloudbreak.dto.StackDto; +import com.sequenceiq.cloudbreak.rotation.service.SecretRotationValidator; import com.sequenceiq.cloudbreak.service.StackUpdater; import com.sequenceiq.cloudbreak.service.cluster.ClusterService; import com.sequenceiq.cloudbreak.service.cluster.flow.ClusterOperationService; @@ -86,7 +87,6 @@ import com.sequenceiq.environment.api.v1.environment.model.response.EnvironmentStatus; import com.sequenceiq.flow.api.model.FlowIdentifier; import com.sequenceiq.flow.api.model.FlowType; -import com.sequenceiq.flow.rotation.service.SecretRotationValidator; @ExtendWith(MockitoExtension.class) public class StackOperationServiceTest { diff --git a/datalake-api/build.gradle b/datalake-api/build.gradle index b954392ad80..e5c6345166f 100644 --- a/datalake-api/build.gradle +++ b/datalake-api/build.gradle @@ -7,6 +7,7 @@ repositories { } dependencies { + implementation project(':secret-rotation-api') implementation project(':core-api') implementation project(':authorization-common-api') implementation project(":structuredevent-api-cdp") diff --git a/datalake-api/src/main/java/com/sequenceiq/sdx/api/model/SdxSecretRotationRequest.java b/datalake-api/src/main/java/com/sequenceiq/sdx/api/model/SdxSecretRotationRequest.java index 9aba6271014..0eeb8e43b68 100644 --- a/datalake-api/src/main/java/com/sequenceiq/sdx/api/model/SdxSecretRotationRequest.java +++ b/datalake-api/src/main/java/com/sequenceiq/sdx/api/model/SdxSecretRotationRequest.java @@ -7,7 +7,7 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonInclude; import com.sequenceiq.cloudbreak.auth.crn.CrnResourceDescriptor; -import com.sequenceiq.cloudbreak.rotation.secret.RotationFlowExecutionType; +import com.sequenceiq.cloudbreak.rotation.RotationFlowExecutionType; import com.sequenceiq.cloudbreak.validation.ValidCrn; import io.swagger.annotations.ApiModel; diff --git a/datalake-api/src/main/java/com/sequenceiq/sdx/rotation/DatalakeSecretType.java b/datalake-api/src/main/java/com/sequenceiq/sdx/rotation/DatalakeSecretType.java index cf90a0ae113..d4396f207fb 100644 --- a/datalake-api/src/main/java/com/sequenceiq/sdx/rotation/DatalakeSecretType.java +++ b/datalake-api/src/main/java/com/sequenceiq/sdx/rotation/DatalakeSecretType.java @@ -1,12 +1,12 @@ package com.sequenceiq.sdx.rotation; -import static com.sequenceiq.cloudbreak.rotation.secret.step.CommonSecretRotationStep.CLOUDBREAK_ROTATE_POLLING; -import static com.sequenceiq.cloudbreak.rotation.secret.step.CommonSecretRotationStep.REDBEAMS_ROTATE_POLLING; +import static com.sequenceiq.cloudbreak.rotation.CommonSecretRotationStep.CLOUDBREAK_ROTATE_POLLING; +import static com.sequenceiq.cloudbreak.rotation.CommonSecretRotationStep.REDBEAMS_ROTATE_POLLING; import java.util.List; -import com.sequenceiq.cloudbreak.rotation.secret.SecretType; -import com.sequenceiq.cloudbreak.rotation.secret.step.SecretRotationStep; +import com.sequenceiq.cloudbreak.rotation.SecretRotationStep; +import com.sequenceiq.cloudbreak.rotation.SecretType; public enum DatalakeSecretType implements SecretType { diff --git a/datalake/build.gradle b/datalake/build.gradle index 140b3203e5a..52e5972ba02 100644 --- a/datalake/build.gradle +++ b/datalake/build.gradle @@ -51,6 +51,8 @@ configurations { } dependencies { + implementation project(':secret-rotation') + implementation project(':secret-rotation-api') implementation project(':authorization-common') implementation project(':common') implementation project(':flow') diff --git a/datalake/src/main/java/com/sequenceiq/datalake/flow/SdxReactorFlowManager.java b/datalake/src/main/java/com/sequenceiq/datalake/flow/SdxReactorFlowManager.java index 3bb157e463c..e39f43eb08c 100644 --- a/datalake/src/main/java/com/sequenceiq/datalake/flow/SdxReactorFlowManager.java +++ b/datalake/src/main/java/com/sequenceiq/datalake/flow/SdxReactorFlowManager.java @@ -43,8 +43,9 @@ import com.sequenceiq.cloudbreak.exception.CloudbreakApiException; import com.sequenceiq.cloudbreak.exception.FlowNotAcceptedException; import com.sequenceiq.cloudbreak.exception.FlowsAlreadyRunningException; -import com.sequenceiq.cloudbreak.rotation.secret.RotationFlowExecutionType; -import com.sequenceiq.cloudbreak.rotation.secret.SecretType; +import com.sequenceiq.cloudbreak.rotation.RotationFlowExecutionType; +import com.sequenceiq.cloudbreak.rotation.SecretType; +import com.sequenceiq.cloudbreak.rotation.flow.chain.SecretRotationFlowChainTriggerEvent; import com.sequenceiq.datalake.entity.SdxCluster; import com.sequenceiq.datalake.events.EventSenderService; import com.sequenceiq.datalake.flow.cert.renew.event.SdxStartCertRenewalEvent; @@ -83,7 +84,6 @@ import com.sequenceiq.flow.core.model.FlowAcceptResult; import com.sequenceiq.flow.event.EventSelectorUtil; import com.sequenceiq.flow.reactor.ErrorHandlerAwareReactorEventFactory; -import com.sequenceiq.flow.rotation.chain.SecretRotationFlowChainTriggerEvent; import com.sequenceiq.flow.service.FlowNameFormatService; import com.sequenceiq.sdx.api.model.DatalakeHorizontalScaleRequest; import com.sequenceiq.sdx.api.model.SdxRecoveryType; diff --git a/datalake/src/main/java/com/sequenceiq/datalake/rotation/DatalakeSecretRotationInformation.java b/datalake/src/main/java/com/sequenceiq/datalake/rotation/DatalakeSecretRotationInformation.java index fdd2b6cf682..f14771ae456 100644 --- a/datalake/src/main/java/com/sequenceiq/datalake/rotation/DatalakeSecretRotationInformation.java +++ b/datalake/src/main/java/com/sequenceiq/datalake/rotation/DatalakeSecretRotationInformation.java @@ -2,8 +2,8 @@ import org.springframework.stereotype.Component; -import com.sequenceiq.cloudbreak.rotation.secret.SecretType; -import com.sequenceiq.cloudbreak.rotation.secret.application.ApplicationSecretRotationInformation; +import com.sequenceiq.cloudbreak.rotation.SecretType; +import com.sequenceiq.cloudbreak.rotation.config.ApplicationSecretRotationInformation; import com.sequenceiq.sdx.rotation.DatalakeSecretType; @Component diff --git a/datalake/src/main/java/com/sequenceiq/datalake/service/rotation/CloudbreakPollerRotationExecutor.java b/datalake/src/main/java/com/sequenceiq/datalake/service/rotation/CloudbreakPollerRotationExecutor.java index 29542738bdd..e40e0841309 100644 --- a/datalake/src/main/java/com/sequenceiq/datalake/service/rotation/CloudbreakPollerRotationExecutor.java +++ b/datalake/src/main/java/com/sequenceiq/datalake/service/rotation/CloudbreakPollerRotationExecutor.java @@ -1,9 +1,9 @@ package com.sequenceiq.datalake.service.rotation; -import static com.sequenceiq.cloudbreak.rotation.secret.RotationFlowExecutionType.FINALIZE; -import static com.sequenceiq.cloudbreak.rotation.secret.RotationFlowExecutionType.ROLLBACK; -import static com.sequenceiq.cloudbreak.rotation.secret.RotationFlowExecutionType.ROTATE; -import static com.sequenceiq.cloudbreak.rotation.secret.step.CommonSecretRotationStep.CLOUDBREAK_ROTATE_POLLING; +import static com.sequenceiq.cloudbreak.rotation.CommonSecretRotationStep.CLOUDBREAK_ROTATE_POLLING; +import static com.sequenceiq.cloudbreak.rotation.RotationFlowExecutionType.FINALIZE; +import static com.sequenceiq.cloudbreak.rotation.RotationFlowExecutionType.ROLLBACK; +import static com.sequenceiq.cloudbreak.rotation.RotationFlowExecutionType.ROTATE; import javax.inject.Inject; @@ -12,9 +12,9 @@ import org.springframework.stereotype.Component; import com.sequenceiq.cloudbreak.rotation.CloudbreakSecretType; -import com.sequenceiq.cloudbreak.rotation.secret.AbstractRotationExecutor; -import com.sequenceiq.cloudbreak.rotation.secret.context.PollerRotationContext; -import com.sequenceiq.cloudbreak.rotation.secret.step.SecretRotationStep; +import com.sequenceiq.cloudbreak.rotation.SecretRotationStep; +import com.sequenceiq.cloudbreak.rotation.executor.AbstractRotationExecutor; +import com.sequenceiq.cloudbreak.rotation.secret.poller.PollerRotationContext; @Component public class CloudbreakPollerRotationExecutor extends AbstractRotationExecutor { diff --git a/datalake/src/main/java/com/sequenceiq/datalake/service/rotation/RedbeamsPollerRotationExecutor.java b/datalake/src/main/java/com/sequenceiq/datalake/service/rotation/RedbeamsPollerRotationExecutor.java index e7b30f0f32e..bf317ef6aa7 100644 --- a/datalake/src/main/java/com/sequenceiq/datalake/service/rotation/RedbeamsPollerRotationExecutor.java +++ b/datalake/src/main/java/com/sequenceiq/datalake/service/rotation/RedbeamsPollerRotationExecutor.java @@ -1,9 +1,10 @@ package com.sequenceiq.datalake.service.rotation; -import static com.sequenceiq.cloudbreak.rotation.secret.RotationFlowExecutionType.FINALIZE; -import static com.sequenceiq.cloudbreak.rotation.secret.RotationFlowExecutionType.ROLLBACK; -import static com.sequenceiq.cloudbreak.rotation.secret.RotationFlowExecutionType.ROTATE; -import static com.sequenceiq.cloudbreak.rotation.secret.step.CommonSecretRotationStep.REDBEAMS_ROTATE_POLLING; + +import static com.sequenceiq.cloudbreak.rotation.CommonSecretRotationStep.REDBEAMS_ROTATE_POLLING; +import static com.sequenceiq.cloudbreak.rotation.RotationFlowExecutionType.FINALIZE; +import static com.sequenceiq.cloudbreak.rotation.RotationFlowExecutionType.ROLLBACK; +import static com.sequenceiq.cloudbreak.rotation.RotationFlowExecutionType.ROTATE; import javax.inject.Inject; @@ -11,9 +12,9 @@ import org.slf4j.LoggerFactory; import org.springframework.stereotype.Component; -import com.sequenceiq.cloudbreak.rotation.secret.AbstractRotationExecutor; -import com.sequenceiq.cloudbreak.rotation.secret.context.PollerRotationContext; -import com.sequenceiq.cloudbreak.rotation.secret.step.SecretRotationStep; +import com.sequenceiq.cloudbreak.rotation.SecretRotationStep; +import com.sequenceiq.cloudbreak.rotation.executor.AbstractRotationExecutor; +import com.sequenceiq.cloudbreak.rotation.secret.poller.PollerRotationContext; import com.sequenceiq.redbeams.rotation.RedbeamsSecretType; @Component diff --git a/datalake/src/main/java/com/sequenceiq/datalake/service/rotation/SdxRotationService.java b/datalake/src/main/java/com/sequenceiq/datalake/service/rotation/SdxRotationService.java index d0cc8768d27..ddf82b5b35b 100644 --- a/datalake/src/main/java/com/sequenceiq/datalake/service/rotation/SdxRotationService.java +++ b/datalake/src/main/java/com/sequenceiq/datalake/service/rotation/SdxRotationService.java @@ -19,9 +19,10 @@ import com.sequenceiq.cloudbreak.auth.crn.RegionAwareInternalCrnGeneratorFactory; import com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException; import com.sequenceiq.cloudbreak.rotation.CloudbreakSecretType; -import com.sequenceiq.cloudbreak.rotation.secret.RotationFlowExecutionType; -import com.sequenceiq.cloudbreak.rotation.secret.SecretRotationException; -import com.sequenceiq.cloudbreak.rotation.secret.SecretType; +import com.sequenceiq.cloudbreak.rotation.RotationFlowExecutionType; +import com.sequenceiq.cloudbreak.rotation.SecretType; +import com.sequenceiq.cloudbreak.rotation.common.SecretRotationException; +import com.sequenceiq.cloudbreak.rotation.service.SecretRotationValidator; import com.sequenceiq.datalake.entity.SdxCluster; import com.sequenceiq.datalake.flow.SdxReactorFlowManager; import com.sequenceiq.datalake.repository.SdxClusterRepository; @@ -33,7 +34,6 @@ import com.sequenceiq.flow.api.model.FlowIdentifier; import com.sequenceiq.flow.api.model.FlowLogResponse; import com.sequenceiq.flow.api.model.StateStatus; -import com.sequenceiq.flow.rotation.service.SecretRotationValidator; import com.sequenceiq.redbeams.api.endpoint.v4.databaseserver.DatabaseServerV4Endpoint; import com.sequenceiq.redbeams.api.endpoint.v4.databaseserver.requests.RotateDatabaseServerSecretV4Request; import com.sequenceiq.redbeams.rotation.RedbeamsSecretType; diff --git a/datalake/src/main/java/com/sequenceiq/datalake/service/rotation/context/provider/DatalakeCMAdminPasswordRotationContextProvider.java b/datalake/src/main/java/com/sequenceiq/datalake/service/rotation/context/provider/DatalakeCMAdminPasswordRotationContextProvider.java index f34d41b5a3d..5f6152b00af 100644 --- a/datalake/src/main/java/com/sequenceiq/datalake/service/rotation/context/provider/DatalakeCMAdminPasswordRotationContextProvider.java +++ b/datalake/src/main/java/com/sequenceiq/datalake/service/rotation/context/provider/DatalakeCMAdminPasswordRotationContextProvider.java @@ -1,18 +1,18 @@ package com.sequenceiq.datalake.service.rotation.context.provider; import static com.sequenceiq.cloudbreak.rotation.CloudbreakSecretType.CLUSTER_CB_CM_ADMIN_PASSWORD; -import static com.sequenceiq.cloudbreak.rotation.secret.step.CommonSecretRotationStep.CLOUDBREAK_ROTATE_POLLING; +import static com.sequenceiq.cloudbreak.rotation.CommonSecretRotationStep.CLOUDBREAK_ROTATE_POLLING; import static com.sequenceiq.sdx.rotation.DatalakeSecretType.DATALAKE_CB_CM_ADMIN_PASSWORD; import java.util.Map; import org.springframework.stereotype.Component; -import com.sequenceiq.cloudbreak.rotation.secret.RotationContext; -import com.sequenceiq.cloudbreak.rotation.secret.RotationContextProvider; -import com.sequenceiq.cloudbreak.rotation.secret.SecretType; -import com.sequenceiq.cloudbreak.rotation.secret.context.PollerRotationContext; -import com.sequenceiq.cloudbreak.rotation.secret.step.SecretRotationStep; +import com.sequenceiq.cloudbreak.rotation.SecretRotationStep; +import com.sequenceiq.cloudbreak.rotation.SecretType; +import com.sequenceiq.cloudbreak.rotation.common.RotationContext; +import com.sequenceiq.cloudbreak.rotation.common.RotationContextProvider; +import com.sequenceiq.cloudbreak.rotation.secret.poller.PollerRotationContext; @Component public class DatalakeCMAdminPasswordRotationContextProvider implements RotationContextProvider { diff --git a/datalake/src/main/java/com/sequenceiq/datalake/service/rotation/context/provider/DatalakeCMDatabasePasswordRotationContextProvider.java b/datalake/src/main/java/com/sequenceiq/datalake/service/rotation/context/provider/DatalakeCMDatabasePasswordRotationContextProvider.java index da4912f14da..efb3a182341 100644 --- a/datalake/src/main/java/com/sequenceiq/datalake/service/rotation/context/provider/DatalakeCMDatabasePasswordRotationContextProvider.java +++ b/datalake/src/main/java/com/sequenceiq/datalake/service/rotation/context/provider/DatalakeCMDatabasePasswordRotationContextProvider.java @@ -1,7 +1,7 @@ package com.sequenceiq.datalake.service.rotation.context.provider; import static com.sequenceiq.cloudbreak.rotation.CloudbreakSecretType.CLUSTER_CM_DB_PASSWORD; -import static com.sequenceiq.cloudbreak.rotation.secret.step.CommonSecretRotationStep.CLOUDBREAK_ROTATE_POLLING; +import static com.sequenceiq.cloudbreak.rotation.CommonSecretRotationStep.CLOUDBREAK_ROTATE_POLLING; import static com.sequenceiq.sdx.rotation.DatalakeSecretType.DATALAKE_CM_DB_PASSWORD; import java.util.HashMap; @@ -9,11 +9,11 @@ import org.springframework.stereotype.Component; -import com.sequenceiq.cloudbreak.rotation.secret.RotationContext; -import com.sequenceiq.cloudbreak.rotation.secret.RotationContextProvider; -import com.sequenceiq.cloudbreak.rotation.secret.SecretType; -import com.sequenceiq.cloudbreak.rotation.secret.context.PollerRotationContext; -import com.sequenceiq.cloudbreak.rotation.secret.step.SecretRotationStep; +import com.sequenceiq.cloudbreak.rotation.SecretRotationStep; +import com.sequenceiq.cloudbreak.rotation.SecretType; +import com.sequenceiq.cloudbreak.rotation.common.RotationContext; +import com.sequenceiq.cloudbreak.rotation.common.RotationContextProvider; +import com.sequenceiq.cloudbreak.rotation.secret.poller.PollerRotationContext; @Component public class DatalakeCMDatabasePasswordRotationContextProvider implements RotationContextProvider { diff --git a/datalake/src/main/java/com/sequenceiq/datalake/service/rotation/context/provider/DatalakeCMMgmtPasswordRotationContextProvider.java b/datalake/src/main/java/com/sequenceiq/datalake/service/rotation/context/provider/DatalakeCMMgmtPasswordRotationContextProvider.java index 379d802814c..4c774879245 100644 --- a/datalake/src/main/java/com/sequenceiq/datalake/service/rotation/context/provider/DatalakeCMMgmtPasswordRotationContextProvider.java +++ b/datalake/src/main/java/com/sequenceiq/datalake/service/rotation/context/provider/DatalakeCMMgmtPasswordRotationContextProvider.java @@ -1,18 +1,18 @@ package com.sequenceiq.datalake.service.rotation.context.provider; import static com.sequenceiq.cloudbreak.rotation.CloudbreakSecretType.CLUSTER_MGMT_CM_ADMIN_PASSWORD; -import static com.sequenceiq.cloudbreak.rotation.secret.step.CommonSecretRotationStep.CLOUDBREAK_ROTATE_POLLING; +import static com.sequenceiq.cloudbreak.rotation.CommonSecretRotationStep.CLOUDBREAK_ROTATE_POLLING; import static com.sequenceiq.sdx.rotation.DatalakeSecretType.DATALAKE_MGMT_CM_ADMIN_PASSWORD; import java.util.Map; import org.springframework.stereotype.Component; -import com.sequenceiq.cloudbreak.rotation.secret.RotationContext; -import com.sequenceiq.cloudbreak.rotation.secret.RotationContextProvider; -import com.sequenceiq.cloudbreak.rotation.secret.SecretType; -import com.sequenceiq.cloudbreak.rotation.secret.context.PollerRotationContext; -import com.sequenceiq.cloudbreak.rotation.secret.step.SecretRotationStep; +import com.sequenceiq.cloudbreak.rotation.SecretRotationStep; +import com.sequenceiq.cloudbreak.rotation.SecretType; +import com.sequenceiq.cloudbreak.rotation.common.RotationContext; +import com.sequenceiq.cloudbreak.rotation.common.RotationContextProvider; +import com.sequenceiq.cloudbreak.rotation.secret.poller.PollerRotationContext; @Component public class DatalakeCMMgmtPasswordRotationContextProvider implements RotationContextProvider { diff --git a/datalake/src/main/java/com/sequenceiq/datalake/service/rotation/context/provider/DatalakeCMServiceDatabasePasswordRotationContextProvider.java b/datalake/src/main/java/com/sequenceiq/datalake/service/rotation/context/provider/DatalakeCMServiceDatabasePasswordRotationContextProvider.java index d8fb4712615..1f8938488db 100644 --- a/datalake/src/main/java/com/sequenceiq/datalake/service/rotation/context/provider/DatalakeCMServiceDatabasePasswordRotationContextProvider.java +++ b/datalake/src/main/java/com/sequenceiq/datalake/service/rotation/context/provider/DatalakeCMServiceDatabasePasswordRotationContextProvider.java @@ -1,7 +1,7 @@ package com.sequenceiq.datalake.service.rotation.context.provider; import static com.sequenceiq.cloudbreak.rotation.CloudbreakSecretType.CLUSTER_CM_SERVICES_DB_PASSWORD; -import static com.sequenceiq.cloudbreak.rotation.secret.step.CommonSecretRotationStep.CLOUDBREAK_ROTATE_POLLING; +import static com.sequenceiq.cloudbreak.rotation.CommonSecretRotationStep.CLOUDBREAK_ROTATE_POLLING; import static com.sequenceiq.sdx.rotation.DatalakeSecretType.DATALAKE_CM_SERVICE_DB_PASSWORD; import java.util.HashMap; @@ -9,11 +9,11 @@ import org.springframework.stereotype.Component; -import com.sequenceiq.cloudbreak.rotation.secret.RotationContext; -import com.sequenceiq.cloudbreak.rotation.secret.RotationContextProvider; -import com.sequenceiq.cloudbreak.rotation.secret.SecretType; -import com.sequenceiq.cloudbreak.rotation.secret.context.PollerRotationContext; -import com.sequenceiq.cloudbreak.rotation.secret.step.SecretRotationStep; +import com.sequenceiq.cloudbreak.rotation.SecretRotationStep; +import com.sequenceiq.cloudbreak.rotation.SecretType; +import com.sequenceiq.cloudbreak.rotation.common.RotationContext; +import com.sequenceiq.cloudbreak.rotation.common.RotationContextProvider; +import com.sequenceiq.cloudbreak.rotation.secret.poller.PollerRotationContext; @Component public class DatalakeCMServiceDatabasePasswordRotationContextProvider implements RotationContextProvider { diff --git a/datalake/src/main/java/com/sequenceiq/datalake/service/rotation/context/provider/DatalakeExternalDatabaseRootPasswordRotationContextProvider.java b/datalake/src/main/java/com/sequenceiq/datalake/service/rotation/context/provider/DatalakeExternalDatabaseRootPasswordRotationContextProvider.java index 39a1952663b..d341c9bda49 100644 --- a/datalake/src/main/java/com/sequenceiq/datalake/service/rotation/context/provider/DatalakeExternalDatabaseRootPasswordRotationContextProvider.java +++ b/datalake/src/main/java/com/sequenceiq/datalake/service/rotation/context/provider/DatalakeExternalDatabaseRootPasswordRotationContextProvider.java @@ -1,8 +1,8 @@ package com.sequenceiq.datalake.service.rotation.context.provider; import static com.sequenceiq.cloudbreak.rotation.CloudbreakSecretType.DATALAKE_EXTERNAL_DATABASE_ROOT_PASSWORD; -import static com.sequenceiq.cloudbreak.rotation.secret.step.CommonSecretRotationStep.CLOUDBREAK_ROTATE_POLLING; -import static com.sequenceiq.cloudbreak.rotation.secret.step.CommonSecretRotationStep.REDBEAMS_ROTATE_POLLING; +import static com.sequenceiq.cloudbreak.rotation.CommonSecretRotationStep.CLOUDBREAK_ROTATE_POLLING; +import static com.sequenceiq.cloudbreak.rotation.CommonSecretRotationStep.REDBEAMS_ROTATE_POLLING; import static com.sequenceiq.redbeams.rotation.RedbeamsSecretType.REDBEAMS_EXTERNAL_DATABASE_ROOT_PASSWORD; import static com.sequenceiq.sdx.rotation.DatalakeSecretType.DATALAKE_DATABASE_ROOT_PASSWORD; @@ -11,11 +11,11 @@ import org.springframework.stereotype.Component; -import com.sequenceiq.cloudbreak.rotation.secret.RotationContext; -import com.sequenceiq.cloudbreak.rotation.secret.RotationContextProvider; -import com.sequenceiq.cloudbreak.rotation.secret.SecretType; -import com.sequenceiq.cloudbreak.rotation.secret.context.PollerRotationContext; -import com.sequenceiq.cloudbreak.rotation.secret.step.SecretRotationStep; +import com.sequenceiq.cloudbreak.rotation.SecretRotationStep; +import com.sequenceiq.cloudbreak.rotation.SecretType; +import com.sequenceiq.cloudbreak.rotation.common.RotationContext; +import com.sequenceiq.cloudbreak.rotation.common.RotationContextProvider; +import com.sequenceiq.cloudbreak.rotation.secret.poller.PollerRotationContext; @Component public class DatalakeExternalDatabaseRootPasswordRotationContextProvider implements RotationContextProvider { diff --git a/datalake/src/main/java/com/sequenceiq/datalake/service/rotation/context/provider/DatalakeSaltBootSecretsRotationContextProvider.java b/datalake/src/main/java/com/sequenceiq/datalake/service/rotation/context/provider/DatalakeSaltBootSecretsRotationContextProvider.java index ebcf9ff5960..208a92f1ee8 100644 --- a/datalake/src/main/java/com/sequenceiq/datalake/service/rotation/context/provider/DatalakeSaltBootSecretsRotationContextProvider.java +++ b/datalake/src/main/java/com/sequenceiq/datalake/service/rotation/context/provider/DatalakeSaltBootSecretsRotationContextProvider.java @@ -1,17 +1,17 @@ package com.sequenceiq.datalake.service.rotation.context.provider; -import static com.sequenceiq.cloudbreak.rotation.secret.step.CommonSecretRotationStep.CLOUDBREAK_ROTATE_POLLING; +import static com.sequenceiq.cloudbreak.rotation.CommonSecretRotationStep.CLOUDBREAK_ROTATE_POLLING; import java.util.Map; import org.springframework.stereotype.Component; import com.sequenceiq.cloudbreak.rotation.CloudbreakSecretType; -import com.sequenceiq.cloudbreak.rotation.secret.RotationContext; -import com.sequenceiq.cloudbreak.rotation.secret.RotationContextProvider; -import com.sequenceiq.cloudbreak.rotation.secret.SecretType; -import com.sequenceiq.cloudbreak.rotation.secret.context.PollerRotationContext; -import com.sequenceiq.cloudbreak.rotation.secret.step.SecretRotationStep; +import com.sequenceiq.cloudbreak.rotation.SecretRotationStep; +import com.sequenceiq.cloudbreak.rotation.SecretType; +import com.sequenceiq.cloudbreak.rotation.common.RotationContext; +import com.sequenceiq.cloudbreak.rotation.common.RotationContextProvider; +import com.sequenceiq.cloudbreak.rotation.secret.poller.PollerRotationContext; import com.sequenceiq.sdx.rotation.DatalakeSecretType; @Component diff --git a/datalake/src/main/java/com/sequenceiq/datalake/service/rotation/context/provider/DatalakeUserKeyPairRotationContextProvider.java b/datalake/src/main/java/com/sequenceiq/datalake/service/rotation/context/provider/DatalakeUserKeyPairRotationContextProvider.java index 54ad966e9a4..6828baa2ed5 100644 --- a/datalake/src/main/java/com/sequenceiq/datalake/service/rotation/context/provider/DatalakeUserKeyPairRotationContextProvider.java +++ b/datalake/src/main/java/com/sequenceiq/datalake/service/rotation/context/provider/DatalakeUserKeyPairRotationContextProvider.java @@ -1,7 +1,7 @@ package com.sequenceiq.datalake.service.rotation.context.provider; import static com.sequenceiq.cloudbreak.rotation.CloudbreakSecretType.USER_KEYPAIR; -import static com.sequenceiq.cloudbreak.rotation.secret.step.CommonSecretRotationStep.CLOUDBREAK_ROTATE_POLLING; +import static com.sequenceiq.cloudbreak.rotation.CommonSecretRotationStep.CLOUDBREAK_ROTATE_POLLING; import static com.sequenceiq.sdx.rotation.DatalakeSecretType.DATALAKE_USER_KEYPAIR; import java.util.HashMap; @@ -9,11 +9,11 @@ import org.springframework.stereotype.Component; -import com.sequenceiq.cloudbreak.rotation.secret.RotationContext; -import com.sequenceiq.cloudbreak.rotation.secret.RotationContextProvider; -import com.sequenceiq.cloudbreak.rotation.secret.SecretType; -import com.sequenceiq.cloudbreak.rotation.secret.context.PollerRotationContext; -import com.sequenceiq.cloudbreak.rotation.secret.step.SecretRotationStep; +import com.sequenceiq.cloudbreak.rotation.SecretRotationStep; +import com.sequenceiq.cloudbreak.rotation.SecretType; +import com.sequenceiq.cloudbreak.rotation.common.RotationContext; +import com.sequenceiq.cloudbreak.rotation.common.RotationContextProvider; +import com.sequenceiq.cloudbreak.rotation.secret.poller.PollerRotationContext; @Component public class DatalakeUserKeyPairRotationContextProvider implements RotationContextProvider { diff --git a/datalake/src/main/java/com/sequenceiq/datalake/service/sdx/status/SdxSecretRotationStatusService.java b/datalake/src/main/java/com/sequenceiq/datalake/service/sdx/status/SdxSecretRotationStatusService.java index bec18477c59..c5f30a4e836 100644 --- a/datalake/src/main/java/com/sequenceiq/datalake/service/sdx/status/SdxSecretRotationStatusService.java +++ b/datalake/src/main/java/com/sequenceiq/datalake/service/sdx/status/SdxSecretRotationStatusService.java @@ -5,11 +5,11 @@ import org.springframework.context.annotation.Primary; import org.springframework.stereotype.Component; +import com.sequenceiq.cloudbreak.rotation.service.status.SecretRotationStatusService; import com.sequenceiq.datalake.entity.DatalakeStatusEnum; import com.sequenceiq.datalake.entity.SdxCluster; import com.sequenceiq.datalake.entity.SdxStatusEntity; import com.sequenceiq.datalake.service.sdx.SdxService; -import com.sequenceiq.flow.rotation.status.service.SecretRotationStatusService; @Primary @Component diff --git a/datalake/src/test/java/com/sequenceiq/datalake/flow/SdxReactorFlowManagerTest.java b/datalake/src/test/java/com/sequenceiq/datalake/flow/SdxReactorFlowManagerTest.java index 07c86c91d26..ba68ec87c92 100644 --- a/datalake/src/test/java/com/sequenceiq/datalake/flow/SdxReactorFlowManagerTest.java +++ b/datalake/src/test/java/com/sequenceiq/datalake/flow/SdxReactorFlowManagerTest.java @@ -36,6 +36,7 @@ import com.sequenceiq.cloudbreak.eventbus.Event; import com.sequenceiq.cloudbreak.eventbus.EventBus; import com.sequenceiq.cloudbreak.eventbus.Promise; +import com.sequenceiq.cloudbreak.rotation.flow.chain.SecretRotationFlowChainTriggerEvent; import com.sequenceiq.cloudbreak.util.TestConstants; import com.sequenceiq.common.model.FileSystemType; import com.sequenceiq.datalake.entity.SdxCluster; @@ -50,7 +51,6 @@ import com.sequenceiq.flow.event.EventSelectorUtil; import com.sequenceiq.flow.reactor.ErrorHandlerAwareReactorEventFactory; import com.sequenceiq.flow.reactor.api.event.BaseFlowEvent; -import com.sequenceiq.flow.rotation.chain.SecretRotationFlowChainTriggerEvent; import com.sequenceiq.sdx.api.model.SdxClusterShape; import com.sequenceiq.sdx.api.model.SdxUpgradeReplaceVms; import com.sequenceiq.sdx.rotation.DatalakeSecretType; diff --git a/datalake/src/test/java/com/sequenceiq/datalake/service/rotation/CloudbreakPollerRotationExecutorTest.java b/datalake/src/test/java/com/sequenceiq/datalake/service/rotation/CloudbreakPollerRotationExecutorTest.java index 7622b0f326a..4dafb60169b 100644 --- a/datalake/src/test/java/com/sequenceiq/datalake/service/rotation/CloudbreakPollerRotationExecutorTest.java +++ b/datalake/src/test/java/com/sequenceiq/datalake/service/rotation/CloudbreakPollerRotationExecutorTest.java @@ -1,9 +1,9 @@ package com.sequenceiq.datalake.service.rotation; import static com.sequenceiq.cloudbreak.rotation.CloudbreakSecretType.DATALAKE_EXTERNAL_DATABASE_ROOT_PASSWORD; -import static com.sequenceiq.cloudbreak.rotation.secret.RotationFlowExecutionType.FINALIZE; -import static com.sequenceiq.cloudbreak.rotation.secret.RotationFlowExecutionType.ROLLBACK; -import static com.sequenceiq.cloudbreak.rotation.secret.RotationFlowExecutionType.ROTATE; +import static com.sequenceiq.cloudbreak.rotation.RotationFlowExecutionType.FINALIZE; +import static com.sequenceiq.cloudbreak.rotation.RotationFlowExecutionType.ROLLBACK; +import static com.sequenceiq.cloudbreak.rotation.RotationFlowExecutionType.ROTATE; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyString; @@ -15,7 +15,6 @@ import java.util.Optional; -import org.apache.commons.lang3.reflect.FieldUtils; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -24,9 +23,9 @@ import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; -import com.sequenceiq.cloudbreak.rotation.secret.SecretRotationException; -import com.sequenceiq.cloudbreak.rotation.secret.SecretRotationProgressService; -import com.sequenceiq.cloudbreak.rotation.secret.context.PollerRotationContext; +import com.sequenceiq.cloudbreak.rotation.common.SecretRotationException; +import com.sequenceiq.cloudbreak.rotation.secret.poller.PollerRotationContext; +import com.sequenceiq.cloudbreak.rotation.service.progress.SecretRotationStepProgressService; @ExtendWith(MockitoExtension.class) class CloudbreakPollerRotationExecutorTest { @@ -37,14 +36,13 @@ class CloudbreakPollerRotationExecutorTest { private SdxRotationService sdxRotationService; @Mock - private SecretRotationProgressService secretRotationProgressService; + private SecretRotationStepProgressService secretRotationProgressService; @InjectMocks private CloudbreakPollerRotationExecutor underTest; @BeforeEach public void mockProgressService() throws IllegalAccessException { - FieldUtils.writeField(underTest, "secretRotationProgressService", Optional.of(secretRotationProgressService), true); lenient().when(secretRotationProgressService.latestStep(any(), any(), any(), any())).thenReturn(Optional.empty()); } diff --git a/datalake/src/test/java/com/sequenceiq/datalake/service/rotation/RedbeamsPollerRotationExecutorTest.java b/datalake/src/test/java/com/sequenceiq/datalake/service/rotation/RedbeamsPollerRotationExecutorTest.java index f0f4e66503e..8a19df9c5e0 100644 --- a/datalake/src/test/java/com/sequenceiq/datalake/service/rotation/RedbeamsPollerRotationExecutorTest.java +++ b/datalake/src/test/java/com/sequenceiq/datalake/service/rotation/RedbeamsPollerRotationExecutorTest.java @@ -1,8 +1,8 @@ package com.sequenceiq.datalake.service.rotation; -import static com.sequenceiq.cloudbreak.rotation.secret.RotationFlowExecutionType.FINALIZE; -import static com.sequenceiq.cloudbreak.rotation.secret.RotationFlowExecutionType.ROLLBACK; -import static com.sequenceiq.cloudbreak.rotation.secret.RotationFlowExecutionType.ROTATE; +import static com.sequenceiq.cloudbreak.rotation.RotationFlowExecutionType.FINALIZE; +import static com.sequenceiq.cloudbreak.rotation.RotationFlowExecutionType.ROLLBACK; +import static com.sequenceiq.cloudbreak.rotation.RotationFlowExecutionType.ROTATE; import static com.sequenceiq.redbeams.rotation.RedbeamsSecretType.REDBEAMS_EXTERNAL_DATABASE_ROOT_PASSWORD; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.ArgumentMatchers.any; @@ -15,7 +15,6 @@ import java.util.Optional; -import org.apache.commons.lang3.reflect.FieldUtils; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -24,9 +23,9 @@ import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; -import com.sequenceiq.cloudbreak.rotation.secret.SecretRotationException; -import com.sequenceiq.cloudbreak.rotation.secret.SecretRotationProgressService; -import com.sequenceiq.cloudbreak.rotation.secret.context.PollerRotationContext; +import com.sequenceiq.cloudbreak.rotation.common.SecretRotationException; +import com.sequenceiq.cloudbreak.rotation.secret.poller.PollerRotationContext; +import com.sequenceiq.cloudbreak.rotation.service.progress.SecretRotationStepProgressService; @ExtendWith(MockitoExtension.class) class RedbeamsPollerRotationExecutorTest { @@ -37,14 +36,13 @@ class RedbeamsPollerRotationExecutorTest { private SdxRotationService sdxRotationService; @Mock - private SecretRotationProgressService secretRotationProgressService; + private SecretRotationStepProgressService secretRotationProgressService; @InjectMocks private RedbeamsPollerRotationExecutor underTest; @BeforeEach - public void mockProgressService() throws IllegalAccessException { - FieldUtils.writeField(underTest, "secretRotationProgressService", Optional.of(secretRotationProgressService), true); + public void mockProgressService() { lenient().when(secretRotationProgressService.latestStep(any(), any(), any(), any())).thenReturn(Optional.empty()); } diff --git a/datalake/src/test/java/com/sequenceiq/datalake/service/rotation/SdxRotationServiceTest.java b/datalake/src/test/java/com/sequenceiq/datalake/service/rotation/SdxRotationServiceTest.java index 4435e6f157e..5ce8a21ae7c 100644 --- a/datalake/src/test/java/com/sequenceiq/datalake/service/rotation/SdxRotationServiceTest.java +++ b/datalake/src/test/java/com/sequenceiq/datalake/service/rotation/SdxRotationServiceTest.java @@ -1,6 +1,6 @@ package com.sequenceiq.datalake.service.rotation; -import static com.sequenceiq.cloudbreak.rotation.secret.RotationFlowExecutionType.ROTATE; +import static com.sequenceiq.cloudbreak.rotation.RotationFlowExecutionType.ROTATE; import static com.sequenceiq.sdx.rotation.DatalakeSecretType.DATALAKE_DATABASE_ROOT_PASSWORD; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; @@ -31,7 +31,8 @@ import com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException; import com.sequenceiq.cloudbreak.common.exception.NotFoundException; import com.sequenceiq.cloudbreak.rotation.CloudbreakSecretType; -import com.sequenceiq.cloudbreak.rotation.secret.SecretRotationException; +import com.sequenceiq.cloudbreak.rotation.common.SecretRotationException; +import com.sequenceiq.cloudbreak.rotation.service.SecretRotationValidator; import com.sequenceiq.datalake.entity.SdxCluster; import com.sequenceiq.datalake.flow.SdxReactorFlowManager; import com.sequenceiq.datalake.repository.SdxClusterRepository; @@ -43,7 +44,6 @@ import com.sequenceiq.flow.api.model.FlowLogResponse; import com.sequenceiq.flow.api.model.FlowType; import com.sequenceiq.flow.api.model.StateStatus; -import com.sequenceiq.flow.rotation.service.SecretRotationValidator; import com.sequenceiq.redbeams.api.endpoint.v4.databaseserver.DatabaseServerV4Endpoint; import com.sequenceiq.redbeams.rotation.RedbeamsSecretType; diff --git a/datalake/src/test/java/com/sequenceiq/datalake/service/rotation/context/provider/DatalakeExternalDatabaseRootPasswordRotationContextProviderTest.java b/datalake/src/test/java/com/sequenceiq/datalake/service/rotation/context/provider/DatalakeExternalDatabaseRootPasswordRotationContextProviderTest.java index 80126df35cb..303edce81b9 100644 --- a/datalake/src/test/java/com/sequenceiq/datalake/service/rotation/context/provider/DatalakeExternalDatabaseRootPasswordRotationContextProviderTest.java +++ b/datalake/src/test/java/com/sequenceiq/datalake/service/rotation/context/provider/DatalakeExternalDatabaseRootPasswordRotationContextProviderTest.java @@ -11,10 +11,10 @@ import org.mockito.junit.jupiter.MockitoExtension; import com.sequenceiq.cloudbreak.rotation.CloudbreakSecretType; -import com.sequenceiq.cloudbreak.rotation.secret.RotationContext; -import com.sequenceiq.cloudbreak.rotation.secret.context.PollerRotationContext; -import com.sequenceiq.cloudbreak.rotation.secret.step.CommonSecretRotationStep; -import com.sequenceiq.cloudbreak.rotation.secret.step.SecretRotationStep; +import com.sequenceiq.cloudbreak.rotation.CommonSecretRotationStep; +import com.sequenceiq.cloudbreak.rotation.SecretRotationStep; +import com.sequenceiq.cloudbreak.rotation.common.RotationContext; +import com.sequenceiq.cloudbreak.rotation.secret.poller.PollerRotationContext; import com.sequenceiq.redbeams.rotation.RedbeamsSecretType; @ExtendWith(MockitoExtension.class) diff --git a/environment/src/test/java/com/sequenceiq/environment/service/integration/JpaTest.java b/environment/src/test/java/com/sequenceiq/environment/service/integration/JpaTest.java index 6dca64b9e0f..6ed93bb85b5 100644 --- a/environment/src/test/java/com/sequenceiq/environment/service/integration/JpaTest.java +++ b/environment/src/test/java/com/sequenceiq/environment/service/integration/JpaTest.java @@ -24,7 +24,7 @@ @DataJpaTest(properties = { "spring.jpa.properties.hibernate.session_factory.statement_inspector=com.sequenceiq.environment.service.integration.SqlStatementInspector"}) @EntityScan(basePackages = {"com.sequenceiq.flow.domain", - "com.sequenceiq.flow.rotation", + "com.sequenceiq.cloudbreak.rotation", "com.sequenceiq.environment", "com.sequenceiq.cloudbreak.ha.domain", "com.sequenceiq.cloudbreak.structuredevent.domain"}) diff --git a/environment/src/test/java/com/sequenceiq/environment/service/integration/testconfiguration/TestConfigurationForServiceIntegration.java b/environment/src/test/java/com/sequenceiq/environment/service/integration/testconfiguration/TestConfigurationForServiceIntegration.java index 56c06dd1216..5283d22eba4 100644 --- a/environment/src/test/java/com/sequenceiq/environment/service/integration/testconfiguration/TestConfigurationForServiceIntegration.java +++ b/environment/src/test/java/com/sequenceiq/environment/service/integration/testconfiguration/TestConfigurationForServiceIntegration.java @@ -14,7 +14,7 @@ @TestConfiguration @EntityScan(basePackages = {"com.sequenceiq.flow.domain", - "com.sequenceiq.flow.rotation", + "com.sequenceiq.cloudbreak.rotation", "com.sequenceiq.environment", "com.sequenceiq.cloudbreak.ha.domain", "com.sequenceiq.cloudbreak.structuredevent.domain"}) diff --git a/flow/src/main/java/com/sequenceiq/flow/rotation/service/SecretRotationStepProgressService.java b/flow/src/main/java/com/sequenceiq/flow/rotation/service/SecretRotationStepProgressService.java deleted file mode 100644 index 8886faafb80..00000000000 --- a/flow/src/main/java/com/sequenceiq/flow/rotation/service/SecretRotationStepProgressService.java +++ /dev/null @@ -1,56 +0,0 @@ -package com.sequenceiq.flow.rotation.service; - -import java.util.Optional; - -import javax.inject.Inject; - -import org.springframework.stereotype.Service; - -import com.sequenceiq.cloudbreak.rotation.secret.RotationFlowExecutionType; -import com.sequenceiq.cloudbreak.rotation.secret.SecretRotationProgressService; -import com.sequenceiq.cloudbreak.rotation.secret.SecretType; -import com.sequenceiq.cloudbreak.rotation.secret.step.SecretRotationStep; -import com.sequenceiq.flow.rotation.entity.SecretRotationStepProgress; -import com.sequenceiq.flow.rotation.repository.SecretRotationStepProgressRepository; - -@Service -public class SecretRotationStepProgressService implements SecretRotationProgressService { - - @Inject - private Optional repository; - - @Override - public boolean isFinished(SecretRotationStepProgress entity) { - return entity.getFinished() != null; - } - - @Override - public void finished(SecretRotationStepProgress entity) { - repository.ifPresent(repo -> { - entity.setFinished(System.currentTimeMillis()); - repo.save(entity); - }); - } - - @Override - public Optional latestStep(String resourceCrn, SecretType secretType, - SecretRotationStep step, RotationFlowExecutionType executionType) { - if (repository.isPresent()) { - Optional latestStepProgress = repository.get().findAllByResourceCrnAndExecutionType(resourceCrn, executionType) - .stream() - .filter(progress -> secretType.equals(progress.getSecretType()) && step.equals(progress.getSecretRotationStep())) - .findFirst(); - if (latestStepProgress.isEmpty()) { - SecretRotationStepProgress progress = new SecretRotationStepProgress(resourceCrn, secretType, step, executionType, System.currentTimeMillis()); - return Optional.of(repository.get().save(progress)); - } - return latestStepProgress; - } - return Optional.empty(); - } - - @Override - public void deleteAll(String resourceCrn, SecretType secretType) { - repository.ifPresent(repo -> repo.deleteByResourceCrnAndSecretType(resourceCrn, secretType)); - } -} diff --git a/freeipa-api/build.gradle b/freeipa-api/build.gradle index c5c9a485997..15bae0527aa 100644 --- a/freeipa-api/build.gradle +++ b/freeipa-api/build.gradle @@ -15,6 +15,7 @@ jar { } dependencies { + implementation project(':secret-rotation-api') implementation project(':auth-connector') implementation project(':common') implementation project(':common-model') diff --git a/freeipa-api/src/main/java/com/sequenceiq/freeipa/api/rotation/FreeIpaSecretType.java b/freeipa-api/src/main/java/com/sequenceiq/freeipa/api/rotation/FreeIpaSecretType.java index 76d0e4c9a2e..9daedab7711 100644 --- a/freeipa-api/src/main/java/com/sequenceiq/freeipa/api/rotation/FreeIpaSecretType.java +++ b/freeipa-api/src/main/java/com/sequenceiq/freeipa/api/rotation/FreeIpaSecretType.java @@ -1,18 +1,18 @@ package com.sequenceiq.freeipa.api.rotation; -import static com.sequenceiq.cloudbreak.rotation.secret.step.CommonSecretRotationStep.CUSTOM_JOB; -import static com.sequenceiq.cloudbreak.rotation.secret.step.CommonSecretRotationStep.SERVICE_CONFIG; -import static com.sequenceiq.cloudbreak.rotation.secret.step.CommonSecretRotationStep.USER_DATA; -import static com.sequenceiq.cloudbreak.rotation.secret.step.CommonSecretRotationStep.VAULT; +import static com.sequenceiq.cloudbreak.rotation.CommonSecretRotationStep.CUSTOM_JOB; +import static com.sequenceiq.cloudbreak.rotation.CommonSecretRotationStep.SALTBOOT_CONFIG; +import static com.sequenceiq.cloudbreak.rotation.CommonSecretRotationStep.USER_DATA; +import static com.sequenceiq.cloudbreak.rotation.CommonSecretRotationStep.VAULT; import java.util.List; -import com.sequenceiq.cloudbreak.rotation.secret.SecretType; -import com.sequenceiq.cloudbreak.rotation.secret.step.SecretRotationStep; +import com.sequenceiq.cloudbreak.rotation.SecretRotationStep; +import com.sequenceiq.cloudbreak.rotation.SecretType; public enum FreeIpaSecretType implements SecretType { - SALT_BOOT_SECRETS(List.of(VAULT, CUSTOM_JOB, SERVICE_CONFIG, USER_DATA)); + SALT_BOOT_SECRETS(List.of(VAULT, CUSTOM_JOB, SALTBOOT_CONFIG, USER_DATA)); private final List steps; diff --git a/freeipa-api/src/main/java/com/sequenceiq/freeipa/api/v1/freeipa/stack/model/rotate/FreeIpaSecretRotationRequest.java b/freeipa-api/src/main/java/com/sequenceiq/freeipa/api/v1/freeipa/stack/model/rotate/FreeIpaSecretRotationRequest.java index 8237aa2809e..3e79005a0f4 100644 --- a/freeipa-api/src/main/java/com/sequenceiq/freeipa/api/v1/freeipa/stack/model/rotate/FreeIpaSecretRotationRequest.java +++ b/freeipa-api/src/main/java/com/sequenceiq/freeipa/api/v1/freeipa/stack/model/rotate/FreeIpaSecretRotationRequest.java @@ -7,7 +7,7 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonInclude; -import com.sequenceiq.cloudbreak.rotation.secret.RotationFlowExecutionType; +import com.sequenceiq.cloudbreak.rotation.RotationFlowExecutionType; import io.swagger.annotations.ApiModel; diff --git a/freeipa/build.gradle b/freeipa/build.gradle index fafb533c267..d1c8d490cde 100644 --- a/freeipa/build.gradle +++ b/freeipa/build.gradle @@ -115,6 +115,8 @@ dependencies { testImplementation group: 'org.mockito', name: 'mockito-inline', version: mockitoVersion } + implementation project(':secret-rotation') + implementation project(':secret-rotation-api') implementation project(":structuredevent-service-cdp") implementation project(':structuredevent-model') implementation project(':audit-connector') diff --git a/freeipa/src/main/java/com/sequenceiq/freeipa/service/rotation/FreeIpaApplicationSecretRotationInformation.java b/freeipa/src/main/java/com/sequenceiq/freeipa/service/rotation/FreeIpaApplicationSecretRotationInformation.java index 78ea7e7f132..2ffd6e2bd21 100644 --- a/freeipa/src/main/java/com/sequenceiq/freeipa/service/rotation/FreeIpaApplicationSecretRotationInformation.java +++ b/freeipa/src/main/java/com/sequenceiq/freeipa/service/rotation/FreeIpaApplicationSecretRotationInformation.java @@ -2,8 +2,8 @@ import org.springframework.stereotype.Component; -import com.sequenceiq.cloudbreak.rotation.secret.SecretType; -import com.sequenceiq.cloudbreak.rotation.secret.application.ApplicationSecretRotationInformation; +import com.sequenceiq.cloudbreak.rotation.SecretType; +import com.sequenceiq.cloudbreak.rotation.config.ApplicationSecretRotationInformation; import com.sequenceiq.freeipa.api.rotation.FreeIpaSecretType; @Component diff --git a/freeipa/src/main/java/com/sequenceiq/freeipa/service/rotation/saltboot/SaltBootRotationContextProvider.java b/freeipa/src/main/java/com/sequenceiq/freeipa/service/rotation/context/provider/SaltBootRotationContextProvider.java similarity index 81% rename from freeipa/src/main/java/com/sequenceiq/freeipa/service/rotation/saltboot/SaltBootRotationContextProvider.java rename to freeipa/src/main/java/com/sequenceiq/freeipa/service/rotation/context/provider/SaltBootRotationContextProvider.java index 83fbbba5845..88fb13a4898 100644 --- a/freeipa/src/main/java/com/sequenceiq/freeipa/service/rotation/saltboot/SaltBootRotationContextProvider.java +++ b/freeipa/src/main/java/com/sequenceiq/freeipa/service/rotation/context/provider/SaltBootRotationContextProvider.java @@ -1,9 +1,9 @@ -package com.sequenceiq.freeipa.service.rotation.saltboot; +package com.sequenceiq.freeipa.service.rotation.context.provider; -import static com.sequenceiq.cloudbreak.rotation.secret.step.CommonSecretRotationStep.CUSTOM_JOB; -import static com.sequenceiq.cloudbreak.rotation.secret.step.CommonSecretRotationStep.SERVICE_CONFIG; -import static com.sequenceiq.cloudbreak.rotation.secret.step.CommonSecretRotationStep.USER_DATA; -import static com.sequenceiq.cloudbreak.rotation.secret.step.CommonSecretRotationStep.VAULT; +import static com.sequenceiq.cloudbreak.rotation.CommonSecretRotationStep.CUSTOM_JOB; +import static com.sequenceiq.cloudbreak.rotation.CommonSecretRotationStep.SALTBOOT_CONFIG; +import static com.sequenceiq.cloudbreak.rotation.CommonSecretRotationStep.USER_DATA; +import static com.sequenceiq.cloudbreak.rotation.CommonSecretRotationStep.VAULT; import java.security.PublicKey; import java.util.List; @@ -20,16 +20,14 @@ import com.google.common.io.BaseEncoding; import com.sequenceiq.cloudbreak.auth.crn.Crn; import com.sequenceiq.cloudbreak.certificate.PkiUtil; -import com.sequenceiq.cloudbreak.cloud.rotation.UserDataRotationContext; -import com.sequenceiq.cloudbreak.orchestrator.rotation.ServiceConfigRotationContext; -import com.sequenceiq.cloudbreak.orchestrator.rotation.ServiceUpdateConfiguration; -import com.sequenceiq.cloudbreak.orchestrator.salt.rotation.SaltBootPasswordUserDataModifier; -import com.sequenceiq.cloudbreak.orchestrator.salt.rotation.SaltBootSignKeyUserDataModifier; -import com.sequenceiq.cloudbreak.rotation.secret.RotationContext; -import com.sequenceiq.cloudbreak.rotation.secret.RotationContextProvider; -import com.sequenceiq.cloudbreak.rotation.secret.SecretType; -import com.sequenceiq.cloudbreak.rotation.secret.context.CustomJobRotationContext; -import com.sequenceiq.cloudbreak.rotation.secret.step.SecretRotationStep; +import com.sequenceiq.cloudbreak.rotation.SecretRotationStep; +import com.sequenceiq.cloudbreak.rotation.SecretType; +import com.sequenceiq.cloudbreak.rotation.common.RotationContext; +import com.sequenceiq.cloudbreak.rotation.common.RotationContextProvider; +import com.sequenceiq.cloudbreak.rotation.secret.custom.CustomJobRotationContext; +import com.sequenceiq.cloudbreak.rotation.secret.saltboot.SaltBootPasswordUserDataModifier; +import com.sequenceiq.cloudbreak.rotation.secret.saltboot.SaltBootSignKeyUserDataModifier; +import com.sequenceiq.cloudbreak.rotation.secret.userdata.UserDataRotationContext; import com.sequenceiq.cloudbreak.rotation.secret.vault.VaultRotationContext; import com.sequenceiq.cloudbreak.service.secret.domain.RotationSecret; import com.sequenceiq.cloudbreak.service.secret.service.SecretService; @@ -41,6 +39,8 @@ import com.sequenceiq.freeipa.orchestrator.StackBasedExitCriteriaModel; import com.sequenceiq.freeipa.service.GatewayConfigService; import com.sequenceiq.freeipa.service.SecurityConfigService; +import com.sequenceiq.freeipa.service.rotation.context.saltboot.SaltBootConfigRotationContext; +import com.sequenceiq.freeipa.service.rotation.context.saltboot.SaltBootUpdateConfiguration; import com.sequenceiq.freeipa.service.stack.StackService; @Component @@ -83,9 +83,9 @@ public Map getContexts(String resourceId) { String saltBootPasswordSecret = securityConfig.getSaltSecurityConfig().getSaltBootPasswordVaultSecret(); String saltBootPrivateKeySecret = securityConfig.getSaltSecurityConfig().getSaltBootSignPrivateKeyVaultSecret(); return ImmutableMap.builder() - .put(VAULT, getVaultRotationContext(saltBootPasswordSecret, saltBootPrivateKeySecret)) + .put(VAULT, getVaultRotationContext(resourceId, saltBootPasswordSecret, saltBootPrivateKeySecret)) .put(CUSTOM_JOB, getUpdateDatabaseJob(resourceId, environmentCrn.getAccountId(), saltBootPasswordSecret, saltBootPrivateKeySecret)) - .put(SERVICE_CONFIG, getServiceConfigRotationContext(stack, saltBootPasswordSecret, saltBootPrivateKeySecret)) + .put(SALTBOOT_CONFIG, getServiceConfigRotationContext(stack, saltBootPasswordSecret, saltBootPrivateKeySecret)) .put(USER_DATA, new UserDataRotationContext(resourceId, List.of(Pair.of(saltBootPasswordUserDataModifier, saltBootPasswordSecret), Pair.of(saltBootSignKeyUserDataModifier, saltBootPrivateKeySecret)))) @@ -130,18 +130,18 @@ public SecretType getSecret() { return FreeIpaSecretType.SALT_BOOT_SECRETS; } - private ServiceConfigRotationContext getServiceConfigRotationContext(Stack stack, String saltBootPasswordSecret, String saltBootPrivateKeySecret) { - return new ServiceConfigRotationContext(stack.getResourceCrn()) { + private SaltBootConfigRotationContext getServiceConfigRotationContext(Stack stack, String saltBootPasswordSecret, String saltBootPrivateKeySecret) { + return new SaltBootConfigRotationContext(stack.getResourceCrn()) { @Override - public ServiceUpdateConfiguration getServiceUpdateConfiguration() { + public SaltBootUpdateConfiguration getServiceUpdateConfiguration() { RotationSecret saltBootPassword = secretService.getRotation(saltBootPasswordSecret); RotationSecret saltBootPrivateKey = secretService.getRotation(saltBootPrivateKeySecret); String oldSaltBootPassword = saltBootPassword.isRotation() ? saltBootPassword.getBackupSecret() : saltBootPassword.getSecret(); String newSaltBootPassword = saltBootPassword.getSecret(); String oldSaltBootPrivateKey = saltBootPrivateKey.isRotation() ? saltBootPrivateKey.getBackupSecret() : saltBootPrivateKey.getSecret(); String newSaltBootPrivateKey = saltBootPrivateKey.getSecret(); - return new ServiceUpdateConfiguration( + return new SaltBootUpdateConfiguration( gatewayConfigService.getPrimaryGatewayConfig(stack), oldSaltBootPassword, newSaltBootPassword, @@ -176,8 +176,9 @@ private String generateSaltBootSecretConfig(String password, String privateKey) .replace("$PUBLIC_KEY", BASE64.encode(PkiUtil.getPublicKeyDer(new String(BASE64.decode(privateKey))))); } - private VaultRotationContext getVaultRotationContext(String saltBootPasswordSecret, String saltBootPrivateKeySecret) { + private VaultRotationContext getVaultRotationContext(String resourceCrn, String saltBootPasswordSecret, String saltBootPrivateKeySecret) { return VaultRotationContext.builder() + .withResourceCrn(resourceCrn) .withVaultPathSecretMap(ImmutableMap.builder() .put(saltBootPasswordSecret, PasswordUtil.generatePassword()) .put(saltBootPrivateKeySecret, BaseEncoding.base64().encode(PkiUtil.convert(PkiUtil.generateKeypair().getPrivate()).getBytes())) diff --git a/freeipa/src/main/java/com/sequenceiq/freeipa/service/rotation/context/saltboot/SaltBootConfigRotationContext.java b/freeipa/src/main/java/com/sequenceiq/freeipa/service/rotation/context/saltboot/SaltBootConfigRotationContext.java new file mode 100644 index 00000000000..44fd71b920a --- /dev/null +++ b/freeipa/src/main/java/com/sequenceiq/freeipa/service/rotation/context/saltboot/SaltBootConfigRotationContext.java @@ -0,0 +1,12 @@ +package com.sequenceiq.freeipa.service.rotation.context.saltboot; + +import com.sequenceiq.cloudbreak.rotation.common.RotationContext; + +public abstract class SaltBootConfigRotationContext extends RotationContext { + + public SaltBootConfigRotationContext(String resourceCrn) { + super(resourceCrn); + } + + public abstract SaltBootUpdateConfiguration getServiceUpdateConfiguration(); +} diff --git a/freeipa/src/main/java/com/sequenceiq/freeipa/service/rotation/context/saltboot/SaltBootUpdateConfiguration.java b/freeipa/src/main/java/com/sequenceiq/freeipa/service/rotation/context/saltboot/SaltBootUpdateConfiguration.java new file mode 100644 index 00000000000..52c72d1c0cf --- /dev/null +++ b/freeipa/src/main/java/com/sequenceiq/freeipa/service/rotation/context/saltboot/SaltBootUpdateConfiguration.java @@ -0,0 +1,24 @@ +package com.sequenceiq.freeipa.service.rotation.context.saltboot; + +import java.util.List; +import java.util.Set; + +import com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig; +import com.sequenceiq.cloudbreak.orchestrator.state.ExitCriteriaModel; + +public record SaltBootUpdateConfiguration( + GatewayConfig primaryGatewayConfig, + String oldSaltBootPassword, + String newSaltBootPassword, + String oldSaltBootPrivateKey, + String newSaltBootPrivateKey, + String configFolder, + String configFile, + String newConfig, + String oldConfig, + Set targetPrivateIps, + Set targetFqdns, + List serviceRestartActions, + int maxRetryCount, + ExitCriteriaModel exitCriteriaModel) { +} diff --git a/freeipa/src/main/java/com/sequenceiq/freeipa/service/rotation/executor/SaltBootConfigRotationExecutor.java b/freeipa/src/main/java/com/sequenceiq/freeipa/service/rotation/executor/SaltBootConfigRotationExecutor.java new file mode 100644 index 00000000000..0eb418fde6a --- /dev/null +++ b/freeipa/src/main/java/com/sequenceiq/freeipa/service/rotation/executor/SaltBootConfigRotationExecutor.java @@ -0,0 +1,161 @@ +package com.sequenceiq.freeipa.service.rotation.executor; + +import static com.sequenceiq.cloudbreak.rotation.CommonSecretRotationStep.SALTBOOT_CONFIG; + +import java.nio.charset.StandardCharsets; +import java.util.Optional; + +import javax.inject.Inject; + +import org.apache.commons.collections4.CollectionUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Component; + +import com.google.common.io.BaseEncoding; +import com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException; +import com.sequenceiq.cloudbreak.orchestrator.host.HostOrchestrator; +import com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig; +import com.sequenceiq.cloudbreak.rotation.SecretRotationStep; +import com.sequenceiq.cloudbreak.rotation.common.SecretRotationException; +import com.sequenceiq.cloudbreak.rotation.executor.AbstractRotationExecutor; +import com.sequenceiq.freeipa.service.rotation.context.saltboot.SaltBootConfigRotationContext; +import com.sequenceiq.freeipa.service.rotation.context.saltboot.SaltBootUpdateConfiguration; + +@Component +public class SaltBootConfigRotationExecutor extends AbstractRotationExecutor { + + private static final Logger LOGGER = LoggerFactory.getLogger(SaltBootConfigRotationExecutor.class); + + private static final BaseEncoding BASE64 = BaseEncoding.base64(); + + @Inject + private HostOrchestrator hostOrchestrator; + + @Override + public void rotate(SaltBootConfigRotationContext rotationContext) { + SaltBootUpdateConfiguration saltBootUpdateConfiguration = rotationContext.getServiceUpdateConfiguration(); + GatewayConfig gatewayConfig = getUsableGatewayConfig(saltBootUpdateConfiguration); + uploadFile(saltBootUpdateConfiguration, gatewayConfig, saltBootUpdateConfiguration.newConfig()); + restartSaltBootService(saltBootUpdateConfiguration, gatewayConfig); + } + + @Override + public void rollback(SaltBootConfigRotationContext rotationContext) { + SaltBootUpdateConfiguration saltBootUpdateConfiguration = rotationContext.getServiceUpdateConfiguration(); + GatewayConfig gatewayConfig = getUsableGatewayConfig(saltBootUpdateConfiguration); + uploadFile(saltBootUpdateConfiguration, gatewayConfig, saltBootUpdateConfiguration.oldConfig()); + restartSaltBootService(saltBootUpdateConfiguration, gatewayConfig); + } + + @Override + public void finalize(SaltBootConfigRotationContext rotationContext) { + + } + + @Override + public void preValidate(SaltBootConfigRotationContext rotationContext) throws Exception { + + } + + @Override + public void postValidate(SaltBootConfigRotationContext rotationContext) throws Exception { + + } + + @Override + public SecretRotationStep getType() { + return SALTBOOT_CONFIG; + } + + @Override + public Class getContextClass() { + return SaltBootConfigRotationContext.class; + } + + private GatewayConfig getUsableGatewayConfig(SaltBootUpdateConfiguration saltBootUpdateConfiguration) { + GatewayConfig oldPrimaryGatewayConfig = withOldSecrets(saltBootUpdateConfiguration.primaryGatewayConfig(), saltBootUpdateConfiguration); + LOGGER.info("Checking if salt boot is reachable with old secrets."); + if (isSaltBootReachableWithGatewayConfig(saltBootUpdateConfiguration, oldPrimaryGatewayConfig)) { + LOGGER.info("Using old salt boot credentials for file upload."); + return oldPrimaryGatewayConfig; + } + GatewayConfig newPrimaryGatewayConfig = withNewSecrets(saltBootUpdateConfiguration.primaryGatewayConfig(), saltBootUpdateConfiguration); + if (isSaltBootReachableWithGatewayConfig(saltBootUpdateConfiguration, newPrimaryGatewayConfig)) { + LOGGER.info("Using new salt boot credentials for file upload."); + return newPrimaryGatewayConfig; + } + throw new SecretRotationException(String.format( + "Salt boot is not reachable with old nor with new secrets. %s/%s service config can't be updated.", + saltBootUpdateConfiguration.configFolder(), saltBootUpdateConfiguration.configFile()), + getType()); + } + + private boolean isSaltBootReachableWithGatewayConfig(SaltBootUpdateConfiguration saltBootUpdateConfiguration, GatewayConfig gatewayConfig) { + try { + hostOrchestrator.uploadFile( + gatewayConfig, + saltBootUpdateConfiguration.targetPrivateIps(), + saltBootUpdateConfiguration.exitCriteriaModel(), + "/tmp", + "saltboottest-" + System.currentTimeMillis(), + "test".getBytes(StandardCharsets.UTF_8)); + LOGGER.info("Salt boot is reachable with gateway config."); + return true; + } catch (CloudbreakOrchestratorFailedException e) { + LOGGER.info("Salt boot is not reachable with gateway config.", e); + return false; + } + } + + private void uploadFile(SaltBootUpdateConfiguration saltBootUpdateConfiguration, GatewayConfig gatewayConfig, String fileContent) { + try { + hostOrchestrator.uploadFile( + gatewayConfig, + saltBootUpdateConfiguration.targetPrivateIps(), + saltBootUpdateConfiguration.exitCriteriaModel(), + saltBootUpdateConfiguration.configFolder(), + saltBootUpdateConfiguration.configFile(), + fileContent.getBytes(StandardCharsets.UTF_8)); + LOGGER.info("Uploaded service configuration to {}/{} on hosts {}", + saltBootUpdateConfiguration.configFolder(), saltBootUpdateConfiguration.configFile(), saltBootUpdateConfiguration.targetPrivateIps()); + } catch (CloudbreakOrchestratorFailedException e) { + LOGGER.error("Couldn't upload service configuration to {}/{} on hosts {}", + saltBootUpdateConfiguration.configFolder(), saltBootUpdateConfiguration.configFile(), saltBootUpdateConfiguration.targetPrivateIps(), + e); + throw new SecretRotationException(e, getType()); + } + } + + private void restartSaltBootService(SaltBootUpdateConfiguration serviceConfig, GatewayConfig gatewayConfig) { + if (CollectionUtils.isNotEmpty(serviceConfig.serviceRestartActions())) { + try { + LOGGER.info("Executing restart actions {} on hosts {}", serviceConfig.serviceRestartActions(), serviceConfig.targetFqdns()); + hostOrchestrator.executeSaltState( + gatewayConfig, + serviceConfig.targetFqdns(), + serviceConfig.serviceRestartActions(), + serviceConfig.exitCriteriaModel(), + Optional.of(serviceConfig.maxRetryCount()), + Optional.of(serviceConfig.maxRetryCount())); + } catch (CloudbreakOrchestratorFailedException e) { + throw new SecretRotationException(e, getType()); + } + } + } + + private GatewayConfig withOldSecrets(GatewayConfig gatewayConfig, SaltBootUpdateConfiguration saltBootUpdateConfiguration) { + return changeGatewayConfig(gatewayConfig, saltBootUpdateConfiguration.oldSaltBootPassword(), saltBootUpdateConfiguration.oldSaltBootPrivateKey()); + } + + private GatewayConfig withNewSecrets(GatewayConfig gatewayConfig, SaltBootUpdateConfiguration saltBootUpdateConfiguration) { + return changeGatewayConfig(gatewayConfig, saltBootUpdateConfiguration.newSaltBootPassword(), saltBootUpdateConfiguration.newSaltBootPrivateKey()); + } + + private GatewayConfig changeGatewayConfig(GatewayConfig gatewayConfig, String saltBootPassword, String saltBootPrivateKey) { + return gatewayConfig.toBuilder() + .withSaltBootPassword(saltBootPassword) + .withSignatureKey(new String(BASE64.decode(saltBootPrivateKey))) + .build(); + } +} diff --git a/freeipa/src/main/java/com/sequenceiq/freeipa/service/rotation/executor/UserDataRotationExecutor.java b/freeipa/src/main/java/com/sequenceiq/freeipa/service/rotation/executor/UserDataRotationExecutor.java index 9e89d127e48..c8d6936fe32 100644 --- a/freeipa/src/main/java/com/sequenceiq/freeipa/service/rotation/executor/UserDataRotationExecutor.java +++ b/freeipa/src/main/java/com/sequenceiq/freeipa/service/rotation/executor/UserDataRotationExecutor.java @@ -3,7 +3,7 @@ import static com.sequenceiq.cloudbreak.cloud.model.AvailabilityZone.availabilityZone; import static com.sequenceiq.cloudbreak.cloud.model.Location.location; import static com.sequenceiq.cloudbreak.cloud.model.Region.region; -import static com.sequenceiq.cloudbreak.rotation.secret.step.CommonSecretRotationStep.USER_DATA; +import static com.sequenceiq.cloudbreak.rotation.CommonSecretRotationStep.USER_DATA; import java.util.List; import java.util.Map; @@ -26,10 +26,10 @@ import com.sequenceiq.cloudbreak.cloud.model.CloudCredential; import com.sequenceiq.cloudbreak.cloud.model.CloudResource; import com.sequenceiq.cloudbreak.cloud.model.CloudStack; -import com.sequenceiq.cloudbreak.cloud.rotation.UserDataRotationContext; -import com.sequenceiq.cloudbreak.rotation.secret.AbstractRotationExecutor; -import com.sequenceiq.cloudbreak.rotation.secret.SecretRotationException; -import com.sequenceiq.cloudbreak.rotation.secret.step.SecretRotationStep; +import com.sequenceiq.cloudbreak.rotation.SecretRotationStep; +import com.sequenceiq.cloudbreak.rotation.common.SecretRotationException; +import com.sequenceiq.cloudbreak.rotation.executor.AbstractRotationExecutor; +import com.sequenceiq.cloudbreak.rotation.secret.userdata.UserDataRotationContext; import com.sequenceiq.cloudbreak.rotation.secret.userdata.UserDataSecretModifier; import com.sequenceiq.cloudbreak.service.secret.domain.RotationSecret; import com.sequenceiq.cloudbreak.service.secret.service.SecretService; diff --git a/freeipa/src/main/java/com/sequenceiq/freeipa/service/stack/FreeIpaSecretRotationService.java b/freeipa/src/main/java/com/sequenceiq/freeipa/service/stack/FreeIpaSecretRotationService.java index f592a68c961..e38bbef2cbb 100644 --- a/freeipa/src/main/java/com/sequenceiq/freeipa/service/stack/FreeIpaSecretRotationService.java +++ b/freeipa/src/main/java/com/sequenceiq/freeipa/service/stack/FreeIpaSecretRotationService.java @@ -10,11 +10,11 @@ import com.sequenceiq.cloudbreak.auth.altus.EntitlementService; import com.sequenceiq.cloudbreak.common.exception.BadRequestException; -import com.sequenceiq.cloudbreak.rotation.secret.SecretType; +import com.sequenceiq.cloudbreak.rotation.SecretType; +import com.sequenceiq.cloudbreak.rotation.flow.chain.SecretRotationFlowChainTriggerEvent; +import com.sequenceiq.cloudbreak.rotation.service.SecretRotationValidator; import com.sequenceiq.flow.api.model.FlowIdentifier; import com.sequenceiq.flow.event.EventSelectorUtil; -import com.sequenceiq.flow.rotation.chain.SecretRotationFlowChainTriggerEvent; -import com.sequenceiq.flow.rotation.service.SecretRotationValidator; import com.sequenceiq.freeipa.api.rotation.FreeIpaSecretType; import com.sequenceiq.freeipa.api.v1.freeipa.stack.model.rotate.FreeIpaSecretRotationRequest; import com.sequenceiq.freeipa.entity.Stack; diff --git a/freeipa/src/test/java/com/sequenceiq/freeipa/service/rotation/SaltBootRotationContextProviderTest.java b/freeipa/src/test/java/com/sequenceiq/freeipa/service/rotation/context/provider/SaltBootRotationContextProviderTest.java similarity index 78% rename from freeipa/src/test/java/com/sequenceiq/freeipa/service/rotation/SaltBootRotationContextProviderTest.java rename to freeipa/src/test/java/com/sequenceiq/freeipa/service/rotation/context/provider/SaltBootRotationContextProviderTest.java index adb42fe7d3f..c7b7153869c 100644 --- a/freeipa/src/test/java/com/sequenceiq/freeipa/service/rotation/SaltBootRotationContextProviderTest.java +++ b/freeipa/src/test/java/com/sequenceiq/freeipa/service/rotation/context/provider/SaltBootRotationContextProviderTest.java @@ -1,4 +1,4 @@ -package com.sequenceiq.freeipa.service.rotation; +package com.sequenceiq.freeipa.service.rotation.context.provider; import static org.junit.jupiter.api.Assertions.assertInstanceOf; import static org.mockito.ArgumentMatchers.any; @@ -14,18 +14,17 @@ import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; -import com.sequenceiq.cloudbreak.cloud.rotation.UserDataRotationContext; -import com.sequenceiq.cloudbreak.orchestrator.rotation.ServiceConfigRotationContext; -import com.sequenceiq.cloudbreak.rotation.secret.RotationContext; -import com.sequenceiq.cloudbreak.rotation.secret.context.CustomJobRotationContext; -import com.sequenceiq.cloudbreak.rotation.secret.step.CommonSecretRotationStep; -import com.sequenceiq.cloudbreak.rotation.secret.step.SecretRotationStep; +import com.sequenceiq.cloudbreak.rotation.CommonSecretRotationStep; +import com.sequenceiq.cloudbreak.rotation.SecretRotationStep; +import com.sequenceiq.cloudbreak.rotation.common.RotationContext; +import com.sequenceiq.cloudbreak.rotation.secret.custom.CustomJobRotationContext; +import com.sequenceiq.cloudbreak.rotation.secret.userdata.UserDataRotationContext; import com.sequenceiq.cloudbreak.rotation.secret.vault.VaultRotationContext; import com.sequenceiq.freeipa.entity.SaltSecurityConfig; import com.sequenceiq.freeipa.entity.SecurityConfig; import com.sequenceiq.freeipa.entity.Stack; import com.sequenceiq.freeipa.service.SecurityConfigService; -import com.sequenceiq.freeipa.service.rotation.saltboot.SaltBootRotationContextProvider; +import com.sequenceiq.freeipa.service.rotation.context.saltboot.SaltBootConfigRotationContext; import com.sequenceiq.freeipa.service.stack.StackService; @ExtendWith(MockitoExtension.class) @@ -70,7 +69,7 @@ public void testSaltBootContextProviderProvidesAllContextData() { assertInstanceOf(VaultRotationContext.class, contexts.get(CommonSecretRotationStep.VAULT)); assertInstanceOf(CustomJobRotationContext.class, contexts.get(CommonSecretRotationStep.CUSTOM_JOB)); - assertInstanceOf(ServiceConfigRotationContext.class, contexts.get(CommonSecretRotationStep.SERVICE_CONFIG)); + assertInstanceOf(SaltBootConfigRotationContext.class, contexts.get(CommonSecretRotationStep.SALTBOOT_CONFIG)); assertInstanceOf(UserDataRotationContext.class, contexts.get(CommonSecretRotationStep.USER_DATA)); } diff --git a/freeipa/src/test/java/com/sequenceiq/freeipa/service/rotation/executor/SaltBootConfigRotationExecutorTest.java b/freeipa/src/test/java/com/sequenceiq/freeipa/service/rotation/executor/SaltBootConfigRotationExecutorTest.java new file mode 100644 index 00000000000..fc7fbc627fa --- /dev/null +++ b/freeipa/src/test/java/com/sequenceiq/freeipa/service/rotation/executor/SaltBootConfigRotationExecutorTest.java @@ -0,0 +1,217 @@ +package com.sequenceiq.freeipa.service.rotation.executor; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.ArgumentMatchers.matches; +import static org.mockito.Mockito.doThrow; +import static org.mockito.Mockito.lenient; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; + +import java.nio.charset.StandardCharsets; +import java.util.List; +import java.util.Optional; +import java.util.Set; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.ArgumentCaptor; +import org.mockito.Captor; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; + +import com.google.common.io.BaseEncoding; +import com.sequenceiq.cloudbreak.certificate.PkiUtil; +import com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException; +import com.sequenceiq.cloudbreak.orchestrator.host.HostOrchestrator; +import com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig; +import com.sequenceiq.cloudbreak.orchestrator.state.ExitCriteriaModel; +import com.sequenceiq.cloudbreak.rotation.common.SecretRotationException; +import com.sequenceiq.cloudbreak.rotation.service.progress.SecretRotationStepProgressService; +import com.sequenceiq.freeipa.service.rotation.context.saltboot.SaltBootConfigRotationContext; +import com.sequenceiq.freeipa.service.rotation.context.saltboot.SaltBootUpdateConfiguration; + +@ExtendWith(MockitoExtension.class) +class SaltBootConfigRotationExecutorTest { + + private static final String RESOURCE_CRN = "resourceCrn"; + + private static final String NEW_PASSWORD = "newPassword"; + + private static final String OLD_PASSWORD = "oldPassword"; + + private static final String NEW_PRIVATE_KEY = newKey(); + + private static final String OLD_PRIVATE_KEY = newKey(); + + private static final String CONFIG_FOLDER = "/folder"; + + private static final String CONFIG_FILE = "config.conf"; + + private static final String NEW_CONFIG = "a=1"; + + private static final String OLD_CONFIG = "a=0"; + + @Mock + private HostOrchestrator hostOrchestrator; + + @Mock + private SecretRotationStepProgressService secretRotationProgressService; + + @InjectMocks + private SaltBootConfigRotationExecutor underTest; + + @Captor + private ArgumentCaptor gatewayConfigCaptor; + + private GatewayConfig gatewayConfig = GatewayConfig.builder().build(); + + @BeforeEach + public void setUp() { + lenient().when(secretRotationProgressService.latestStep(any(), any(), any(), any())).thenReturn(Optional.empty()); + } + + @Test + public void rotateWithOldSaltBootSecrets() throws Exception { + SaltBootConfigRotationContext context = getServiceConfigRotationContext(); + + underTest.rotate(context); + + verifyFileUpload(gatewayConfigCaptor, NEW_CONFIG); + GatewayConfig usedGatewayConfig = gatewayConfigCaptor.getValue(); + assertGateWayConfig(usedGatewayConfig, OLD_PASSWORD, OLD_PRIVATE_KEY); + verifyRestartStatesAreApplied(); + } + + @Test + public void rotateWithNewSaltBootSecrets() throws Exception { + givenSaltBootTestFailsFirstThenCompletes(); + SaltBootConfigRotationContext context = getServiceConfigRotationContext(); + + underTest.rotate(context); + + verifyFileUpload(gatewayConfigCaptor, NEW_CONFIG); + GatewayConfig usedGatewayConfig = gatewayConfigCaptor.getValue(); + assertGateWayConfig(usedGatewayConfig, NEW_PASSWORD, NEW_PRIVATE_KEY); + verifyRestartStatesAreApplied(); + } + + @Test + public void rotateFailsWhenSaltBootIsNotReachable() throws Exception { + givenSaltBootTestFails(); + SaltBootConfigRotationContext context = getServiceConfigRotationContext(); + + SecretRotationException exception = assertThrows(SecretRotationException.class, () -> underTest.rotate(context)); + + assertEquals("Salt boot is not reachable with old nor with new secrets. /folder/config.conf service config can't be updated.", exception.getMessage()); + } + + @Test + public void rollbackWithOldSaltBootSecrets() throws Exception { + SaltBootConfigRotationContext context = getServiceConfigRotationContext(); + + underTest.rollback(context); + + verifyFileUpload(gatewayConfigCaptor, OLD_CONFIG); + GatewayConfig usedGatewayConfig = gatewayConfigCaptor.getValue(); + assertGateWayConfig(usedGatewayConfig, OLD_PASSWORD, OLD_PRIVATE_KEY); + verifyRestartStatesAreApplied(); + } + + @Test + public void rollbackWithNewSaltBootSecrets() throws Exception { + givenSaltBootTestFailsFirstThenCompletes(); + SaltBootConfigRotationContext context = getServiceConfigRotationContext(); + + underTest.rollback(context); + + verifyFileUpload(gatewayConfigCaptor, OLD_CONFIG); + GatewayConfig usedGatewayConfig = gatewayConfigCaptor.getValue(); + assertGateWayConfig(usedGatewayConfig, NEW_PASSWORD, NEW_PRIVATE_KEY); + verifyRestartStatesAreApplied(); + } + + @Test + public void rollbackFailsWhenSaltBootIsNotReachable() throws Exception { + givenSaltBootTestFails(); + SaltBootConfigRotationContext context = getServiceConfigRotationContext(); + + SecretRotationException exception = assertThrows(SecretRotationException.class, () -> underTest.rollback(context)); + + assertEquals("Salt boot is not reachable with old nor with new secrets. /folder/config.conf service config can't be updated.", exception.getMessage()); + } + + private static String newKey() { + return BaseEncoding.base64().encode(PkiUtil.convert(PkiUtil.generateKeypair().getPrivate()).getBytes()); + } + + private void verifyFileUpload(ArgumentCaptor captor, String config) throws CloudbreakOrchestratorFailedException { + verify(hostOrchestrator, times(1)).uploadFile( + captor.capture(), + any(), + any(), + eq(CONFIG_FOLDER), + eq(CONFIG_FILE), + eq(config.getBytes(StandardCharsets.UTF_8))); + } + + private void givenSaltBootTestFails() throws CloudbreakOrchestratorFailedException { + doThrow(CloudbreakOrchestratorFailedException.class) + .when(hostOrchestrator).uploadFile( + any(), + any(), + any(), + eq("/tmp"), + matches("saltboottest-(\\d+)"), + any()); + } + + private void givenSaltBootTestFailsFirstThenCompletes() throws CloudbreakOrchestratorFailedException { + doThrow(CloudbreakOrchestratorFailedException.class) + .doNothing() + .when(hostOrchestrator).uploadFile( + any(), + any(), + any(), + eq("/tmp"), + matches("saltboottest-(\\d+)"), + any()); + } + + private void verifyRestartStatesAreApplied() throws CloudbreakOrchestratorFailedException { + verify(hostOrchestrator).executeSaltState(any(), any(), eq(List.of("stop", "start")), any(), any(), any()); + } + + private void assertGateWayConfig(GatewayConfig gatewayConfig, String expectedPassword, String expectedSigningKey) { + assertEquals(expectedPassword, gatewayConfig.getSaltBootPassword()); + assertEquals(new String(BaseEncoding.base64().decode(expectedSigningKey)), gatewayConfig.getSignatureKey()); + } + + private SaltBootConfigRotationContext getServiceConfigRotationContext() { + return new SaltBootConfigRotationContext(RESOURCE_CRN) { + @Override + public SaltBootUpdateConfiguration getServiceUpdateConfiguration() { + return new SaltBootUpdateConfiguration( + gatewayConfig, + OLD_PASSWORD, + NEW_PASSWORD, + OLD_PRIVATE_KEY, + NEW_PRIVATE_KEY, + CONFIG_FOLDER, + CONFIG_FILE, + NEW_CONFIG, + OLD_CONFIG, + Set.of("0.0.0.0"), + Set.of("host0"), + List.of("stop", "start"), + 3, + mock(ExitCriteriaModel.class)); + } + }; + } +} \ No newline at end of file diff --git a/freeipa/src/test/java/com/sequenceiq/freeipa/service/rotation/UserDataRotationExecutorTest.java b/freeipa/src/test/java/com/sequenceiq/freeipa/service/rotation/executor/UserDataRotationExecutorTest.java similarity index 88% rename from freeipa/src/test/java/com/sequenceiq/freeipa/service/rotation/UserDataRotationExecutorTest.java rename to freeipa/src/test/java/com/sequenceiq/freeipa/service/rotation/executor/UserDataRotationExecutorTest.java index ab767029a6d..6afe87ebd05 100644 --- a/freeipa/src/test/java/com/sequenceiq/freeipa/service/rotation/UserDataRotationExecutorTest.java +++ b/freeipa/src/test/java/com/sequenceiq/freeipa/service/rotation/executor/UserDataRotationExecutorTest.java @@ -1,6 +1,6 @@ -package com.sequenceiq.freeipa.service.rotation; +package com.sequenceiq.freeipa.service.rotation.executor; -import static com.sequenceiq.cloudbreak.rotation.secret.step.CommonSecretRotationStep.USER_DATA; +import static com.sequenceiq.cloudbreak.rotation.CommonSecretRotationStep.USER_DATA; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.ArgumentMatchers.any; @@ -14,7 +14,6 @@ import java.util.List; import java.util.Optional; -import org.apache.commons.lang3.reflect.FieldUtils; import org.apache.commons.lang3.tuple.Pair; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -24,17 +23,16 @@ import org.mockito.junit.jupiter.MockitoExtension; import com.sequenceiq.cloudbreak.cloud.model.CloudStack; -import com.sequenceiq.cloudbreak.cloud.rotation.UserDataRotationContext; -import com.sequenceiq.cloudbreak.rotation.secret.SecretRotationException; -import com.sequenceiq.cloudbreak.rotation.secret.SecretRotationProgressService; +import com.sequenceiq.cloudbreak.rotation.common.SecretRotationException; +import com.sequenceiq.cloudbreak.rotation.secret.userdata.UserDataRotationContext; import com.sequenceiq.cloudbreak.rotation.secret.userdata.UserDataSecretModifier; +import com.sequenceiq.cloudbreak.rotation.service.progress.SecretRotationStepProgressService; import com.sequenceiq.cloudbreak.service.secret.domain.RotationSecret; import com.sequenceiq.cloudbreak.service.secret.service.SecretService; import com.sequenceiq.cloudbreak.util.UserDataReplacer; import com.sequenceiq.freeipa.converter.cloud.StackToCloudStackConverter; import com.sequenceiq.freeipa.entity.Stack; import com.sequenceiq.freeipa.service.image.userdata.UserDataService; -import com.sequenceiq.freeipa.service.rotation.executor.UserDataRotationExecutor; import com.sequenceiq.freeipa.service.stack.StackService; @ExtendWith(MockitoExtension.class) @@ -70,12 +68,11 @@ class UserDataRotationExecutorTest { private CloudStack cloudStack; @Mock - private SecretRotationProgressService secretRotationProgressService; + private SecretRotationStepProgressService secretRotationProgressService; @BeforeEach - public void setUp() throws IllegalAccessException { + public void setUp() { lenient().when(cloudStackConverter.convert(any())).thenReturn(cloudStack); - FieldUtils.writeField(underTest, "secretRotationProgressService", Optional.of(secretRotationProgressService), true); lenient().when(secretRotationProgressService.latestStep(any(), any(), any(), any())).thenReturn(Optional.empty()); } diff --git a/integration-test/build.gradle b/integration-test/build.gradle index 55a8043e0d4..6a4c6d58df1 100644 --- a/integration-test/build.gradle +++ b/integration-test/build.gradle @@ -104,6 +104,9 @@ dependencies { implementation (project(':redbeams-api')) { transitive = false; } + implementation (project(':secret-rotation-api')) { + transitive = false; + } implementation (project(':audit-connector')) { transitive = false; } diff --git a/integration-test/src/main/java/com/sequenceiq/it/cloudbreak/testcase/e2e/distrox/DistroXSecretRotationTest.java b/integration-test/src/main/java/com/sequenceiq/it/cloudbreak/testcase/e2e/distrox/DistroXSecretRotationTest.java index ccec999dc59..21bf86c086a 100644 --- a/integration-test/src/main/java/com/sequenceiq/it/cloudbreak/testcase/e2e/distrox/DistroXSecretRotationTest.java +++ b/integration-test/src/main/java/com/sequenceiq/it/cloudbreak/testcase/e2e/distrox/DistroXSecretRotationTest.java @@ -1,5 +1,6 @@ package com.sequenceiq.it.cloudbreak.testcase.e2e.distrox; + import static com.sequenceiq.cloudbreak.rotation.CloudbreakSecretType.CLUSTER_CB_CM_ADMIN_PASSWORD; import static com.sequenceiq.cloudbreak.rotation.CloudbreakSecretType.CLUSTER_CM_DB_PASSWORD; import static com.sequenceiq.cloudbreak.rotation.CloudbreakSecretType.CLUSTER_CM_SERVICES_DB_PASSWORD; diff --git a/orchestrator-api/src/main/java/com/sequenceiq/cloudbreak/orchestrator/rotation/ServiceConfigRotationContext.java b/orchestrator-api/src/main/java/com/sequenceiq/cloudbreak/orchestrator/rotation/ServiceConfigRotationContext.java deleted file mode 100644 index edbcb5a11be..00000000000 --- a/orchestrator-api/src/main/java/com/sequenceiq/cloudbreak/orchestrator/rotation/ServiceConfigRotationContext.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.sequenceiq.cloudbreak.orchestrator.rotation; - -import com.sequenceiq.cloudbreak.rotation.secret.RotationContext; - -public abstract class ServiceConfigRotationContext extends RotationContext { - - public ServiceConfigRotationContext(String resourceCrn) { - super(resourceCrn); - } - - public abstract ServiceUpdateConfiguration getServiceUpdateConfiguration(); -} diff --git a/orchestrator-api/src/main/java/com/sequenceiq/cloudbreak/orchestrator/rotation/ServiceConfigRotationExecutor.java b/orchestrator-api/src/main/java/com/sequenceiq/cloudbreak/orchestrator/rotation/ServiceConfigRotationExecutor.java deleted file mode 100644 index dcdbb2de2f7..00000000000 --- a/orchestrator-api/src/main/java/com/sequenceiq/cloudbreak/orchestrator/rotation/ServiceConfigRotationExecutor.java +++ /dev/null @@ -1,159 +0,0 @@ -package com.sequenceiq.cloudbreak.orchestrator.rotation; - -import static com.sequenceiq.cloudbreak.rotation.secret.step.CommonSecretRotationStep.SERVICE_CONFIG; - -import java.nio.charset.StandardCharsets; -import java.util.Optional; - -import javax.inject.Inject; - -import org.apache.commons.collections4.CollectionUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.stereotype.Component; - -import com.google.common.io.BaseEncoding; -import com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException; -import com.sequenceiq.cloudbreak.orchestrator.host.HostOrchestrator; -import com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig; -import com.sequenceiq.cloudbreak.rotation.secret.AbstractRotationExecutor; -import com.sequenceiq.cloudbreak.rotation.secret.SecretRotationException; -import com.sequenceiq.cloudbreak.rotation.secret.step.SecretRotationStep; - -@Component -public class ServiceConfigRotationExecutor extends AbstractRotationExecutor { - - private static final Logger LOGGER = LoggerFactory.getLogger(ServiceConfigRotationExecutor.class); - - private static final BaseEncoding BASE64 = BaseEncoding.base64(); - - @Inject - private HostOrchestrator hostOrchestrator; - - @Override - public void rotate(ServiceConfigRotationContext rotationContext) { - ServiceUpdateConfiguration serviceUpdateConfiguration = rotationContext.getServiceUpdateConfiguration(); - GatewayConfig gatewayConfig = getUsableGatewayConfig(serviceUpdateConfiguration); - uploadFile(serviceUpdateConfiguration, gatewayConfig, serviceUpdateConfiguration.newConfig()); - restartSaltBootService(serviceUpdateConfiguration, gatewayConfig); - } - - @Override - public void rollback(ServiceConfigRotationContext rotationContext) { - ServiceUpdateConfiguration serviceUpdateConfiguration = rotationContext.getServiceUpdateConfiguration(); - GatewayConfig gatewayConfig = getUsableGatewayConfig(serviceUpdateConfiguration); - uploadFile(serviceUpdateConfiguration, gatewayConfig, serviceUpdateConfiguration.oldConfig()); - restartSaltBootService(serviceUpdateConfiguration, gatewayConfig); - } - - @Override - public void finalize(ServiceConfigRotationContext rotationContext) { - - } - - @Override - public void preValidate(ServiceConfigRotationContext rotationContext) throws Exception { - - } - - @Override - public void postValidate(ServiceConfigRotationContext rotationContext) throws Exception { - - } - - @Override - public SecretRotationStep getType() { - return SERVICE_CONFIG; - } - - @Override - public Class getContextClass() { - return ServiceConfigRotationContext.class; - } - - private GatewayConfig getUsableGatewayConfig(ServiceUpdateConfiguration serviceUpdateConfiguration) { - GatewayConfig oldPrimaryGatewayConfig = withOldSecrets(serviceUpdateConfiguration.primaryGatewayConfig(), serviceUpdateConfiguration); - LOGGER.info("Checking if salt boot is reachable with old secrets."); - if (isSaltBootReachableWithGatewayConfig(serviceUpdateConfiguration, oldPrimaryGatewayConfig)) { - LOGGER.info("Using old salt boot credentials for file upload."); - return oldPrimaryGatewayConfig; - } - GatewayConfig newPrimaryGatewayConfig = withNewSecrets(serviceUpdateConfiguration.primaryGatewayConfig(), serviceUpdateConfiguration); - if (isSaltBootReachableWithGatewayConfig(serviceUpdateConfiguration, newPrimaryGatewayConfig)) { - LOGGER.info("Using new salt boot credentials for file upload."); - return newPrimaryGatewayConfig; - } - throw new SecretRotationException(String.format( - "Salt boot is not reachable with old nor with new secrets. %s/%s service config can't be updated.", - serviceUpdateConfiguration.configFolder(), serviceUpdateConfiguration.configFile()), - getType()); - } - - private boolean isSaltBootReachableWithGatewayConfig(ServiceUpdateConfiguration serviceUpdateConfiguration, GatewayConfig gatewayConfig) { - try { - hostOrchestrator.uploadFile( - gatewayConfig, - serviceUpdateConfiguration.targetPrivateIps(), - serviceUpdateConfiguration.exitCriteriaModel(), - "/tmp", - "saltboottest-" + System.currentTimeMillis(), - "test".getBytes(StandardCharsets.UTF_8)); - LOGGER.info("Salt boot is reachable with gateway config."); - return true; - } catch (CloudbreakOrchestratorFailedException e) { - LOGGER.info("Salt boot is not reachable with gateway config.", e); - return false; - } - } - - private void uploadFile(ServiceUpdateConfiguration serviceUpdateConfiguration, GatewayConfig gatewayConfig, String fileContent) { - try { - hostOrchestrator.uploadFile( - gatewayConfig, - serviceUpdateConfiguration.targetPrivateIps(), - serviceUpdateConfiguration.exitCriteriaModel(), - serviceUpdateConfiguration.configFolder(), - serviceUpdateConfiguration.configFile(), - fileContent.getBytes(StandardCharsets.UTF_8)); - LOGGER.info("Uploaded service configuration to {}/{} on hosts {}", - serviceUpdateConfiguration.configFolder(), serviceUpdateConfiguration.configFile(), serviceUpdateConfiguration.targetPrivateIps()); - } catch (CloudbreakOrchestratorFailedException e) { - LOGGER.error("Couldn't upload service configuration to {}/{} on hosts {}", - serviceUpdateConfiguration.configFolder(), serviceUpdateConfiguration.configFile(), serviceUpdateConfiguration.targetPrivateIps(), - e); - throw new SecretRotationException(e, getType()); - } - } - - private void restartSaltBootService(ServiceUpdateConfiguration serviceConfig, GatewayConfig gatewayConfig) { - if (CollectionUtils.isNotEmpty(serviceConfig.serviceRestartActions())) { - try { - LOGGER.info("Executing restart actions {} on hosts {}", serviceConfig.serviceRestartActions(), serviceConfig.targetFqdns()); - hostOrchestrator.executeSaltState( - gatewayConfig, - serviceConfig.targetFqdns(), - serviceConfig.serviceRestartActions(), - serviceConfig.exitCriteriaModel(), - Optional.of(serviceConfig.maxRetryCount()), - Optional.of(serviceConfig.maxRetryCount())); - } catch (CloudbreakOrchestratorFailedException e) { - throw new SecretRotationException(e, getType()); - } - } - } - - private GatewayConfig withOldSecrets(GatewayConfig gatewayConfig, ServiceUpdateConfiguration serviceUpdateConfiguration) { - return changeGatewayConfig(gatewayConfig, serviceUpdateConfiguration.oldSaltBootPassword(), serviceUpdateConfiguration.oldSaltBootPrivateKey()); - } - - private GatewayConfig withNewSecrets(GatewayConfig gatewayConfig, ServiceUpdateConfiguration serviceUpdateConfiguration) { - return changeGatewayConfig(gatewayConfig, serviceUpdateConfiguration.newSaltBootPassword(), serviceUpdateConfiguration.newSaltBootPrivateKey()); - } - - private GatewayConfig changeGatewayConfig(GatewayConfig gatewayConfig, String saltBootPassword, String saltBootPrivateKey) { - return gatewayConfig.toBuilder() - .withSaltBootPassword(saltBootPassword) - .withSignatureKey(new String(BASE64.decode(saltBootPrivateKey))) - .build(); - } -} diff --git a/redbeams-api/build.gradle b/redbeams-api/build.gradle index 657c4603c3c..a5860b570fb 100644 --- a/redbeams-api/build.gradle +++ b/redbeams-api/build.gradle @@ -35,6 +35,7 @@ dependencies { // TODO Why?? :) If we would like use common responses like GeneralCollectionV4Response, // TODO please move to some common package instead of use whole core-api dep implementation project(':core-api') + implementation project(':secret-rotation-api') implementation project(':flow-api') implementation project(':common') implementation project(':auth-connector') diff --git a/redbeams-api/src/main/java/com/sequenceiq/redbeams/api/endpoint/v4/databaseserver/requests/RotateDatabaseServerSecretV4Request.java b/redbeams-api/src/main/java/com/sequenceiq/redbeams/api/endpoint/v4/databaseserver/requests/RotateDatabaseServerSecretV4Request.java index 38da2911106..ab669fb3f30 100644 --- a/redbeams-api/src/main/java/com/sequenceiq/redbeams/api/endpoint/v4/databaseserver/requests/RotateDatabaseServerSecretV4Request.java +++ b/redbeams-api/src/main/java/com/sequenceiq/redbeams/api/endpoint/v4/databaseserver/requests/RotateDatabaseServerSecretV4Request.java @@ -4,7 +4,7 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.sequenceiq.cloudbreak.auth.crn.CrnResourceDescriptor; -import com.sequenceiq.cloudbreak.rotation.secret.RotationFlowExecutionType; +import com.sequenceiq.cloudbreak.rotation.RotationFlowExecutionType; import com.sequenceiq.cloudbreak.validation.ValidCrn; import com.sequenceiq.redbeams.doc.ModelDescriptions; diff --git a/redbeams-api/src/main/java/com/sequenceiq/redbeams/rotation/RedbeamsSecretRotationStep.java b/redbeams-api/src/main/java/com/sequenceiq/redbeams/rotation/RedbeamsSecretRotationStep.java index b7d0b115da9..2c2a77c53b5 100644 --- a/redbeams-api/src/main/java/com/sequenceiq/redbeams/rotation/RedbeamsSecretRotationStep.java +++ b/redbeams-api/src/main/java/com/sequenceiq/redbeams/rotation/RedbeamsSecretRotationStep.java @@ -1,6 +1,6 @@ package com.sequenceiq.redbeams.rotation; -import com.sequenceiq.cloudbreak.rotation.secret.step.SecretRotationStep; +import com.sequenceiq.cloudbreak.rotation.SecretRotationStep; public enum RedbeamsSecretRotationStep implements SecretRotationStep { PROVIDER_DATABASE_ROOT_PASSWORD; diff --git a/redbeams-api/src/main/java/com/sequenceiq/redbeams/rotation/RedbeamsSecretType.java b/redbeams-api/src/main/java/com/sequenceiq/redbeams/rotation/RedbeamsSecretType.java index d8605e81f03..5f8db0ffd79 100644 --- a/redbeams-api/src/main/java/com/sequenceiq/redbeams/rotation/RedbeamsSecretType.java +++ b/redbeams-api/src/main/java/com/sequenceiq/redbeams/rotation/RedbeamsSecretType.java @@ -1,12 +1,12 @@ package com.sequenceiq.redbeams.rotation; -import static com.sequenceiq.cloudbreak.rotation.secret.step.CommonSecretRotationStep.VAULT; +import static com.sequenceiq.cloudbreak.rotation.CommonSecretRotationStep.VAULT; import static com.sequenceiq.redbeams.rotation.RedbeamsSecretRotationStep.PROVIDER_DATABASE_ROOT_PASSWORD; import java.util.List; -import com.sequenceiq.cloudbreak.rotation.secret.SecretType; -import com.sequenceiq.cloudbreak.rotation.secret.step.SecretRotationStep; +import com.sequenceiq.cloudbreak.rotation.SecretRotationStep; +import com.sequenceiq.cloudbreak.rotation.SecretType; public enum RedbeamsSecretType implements SecretType { diff --git a/redbeams/build.gradle b/redbeams/build.gradle index 698f1e43b4b..393c0575d69 100644 --- a/redbeams/build.gradle +++ b/redbeams/build.gradle @@ -102,6 +102,8 @@ dependencies { testImplementation group: 'org.springframework.boot', name: 'spring-boot-starter-test', version: springBootVersion } + implementation project(':secret-rotation') + implementation project(':secret-rotation-api') implementation project(':authorization-common') implementation project(':flow') implementation project(':cloud-reactor') diff --git a/redbeams/src/main/java/com/sequenceiq/redbeams/configuration/DatabaseConfig.java b/redbeams/src/main/java/com/sequenceiq/redbeams/configuration/DatabaseConfig.java index 712ebd2a8fa..48315079e77 100644 --- a/redbeams/src/main/java/com/sequenceiq/redbeams/configuration/DatabaseConfig.java +++ b/redbeams/src/main/java/com/sequenceiq/redbeams/configuration/DatabaseConfig.java @@ -122,7 +122,7 @@ public EntityManagerFactory entityManagerFactory() throws SQLException { LocalContainerEntityManagerFactoryBean entityManagerFactory = new LocalContainerEntityManagerFactoryBean(); entityManagerFactory.setPackagesToScan("com.sequenceiq.redbeams", "com.sequenceiq.flow", "com.sequenceiq.cloudbreak.ha", - "com.sequenceiq.cloudbreak.structuredevent.domain"); + "com.sequenceiq.cloudbreak.structuredevent.domain", "com.sequenceiq.cloudbreak.rotation"); entityManagerFactory.setDataSource(dataSource()); entityManagerFactory.setJpaVendorAdapter(jpaVendorAdapter()); diff --git a/redbeams/src/main/java/com/sequenceiq/redbeams/flow/RedbeamsFlowManager.java b/redbeams/src/main/java/com/sequenceiq/redbeams/flow/RedbeamsFlowManager.java index 5ff744c694e..1fcd8454767 100644 --- a/redbeams/src/main/java/com/sequenceiq/redbeams/flow/RedbeamsFlowManager.java +++ b/redbeams/src/main/java/com/sequenceiq/redbeams/flow/RedbeamsFlowManager.java @@ -16,15 +16,15 @@ import com.sequenceiq.cloudbreak.eventbus.EventBus; import com.sequenceiq.cloudbreak.exception.FlowNotAcceptedException; import com.sequenceiq.cloudbreak.exception.FlowsAlreadyRunningException; -import com.sequenceiq.cloudbreak.rotation.secret.RotationFlowExecutionType; -import com.sequenceiq.cloudbreak.rotation.secret.SecretType; +import com.sequenceiq.cloudbreak.rotation.RotationFlowExecutionType; +import com.sequenceiq.cloudbreak.rotation.SecretType; +import com.sequenceiq.cloudbreak.rotation.flow.chain.SecretRotationFlowChainTriggerEvent; import com.sequenceiq.flow.api.model.FlowIdentifier; import com.sequenceiq.flow.api.model.FlowType; import com.sequenceiq.flow.core.FlowConstants; import com.sequenceiq.flow.core.model.FlowAcceptResult; import com.sequenceiq.flow.event.EventSelectorUtil; import com.sequenceiq.flow.reactor.ErrorHandlerAwareReactorEventFactory; -import com.sequenceiq.flow.rotation.chain.SecretRotationFlowChainTriggerEvent; import com.sequenceiq.flow.service.FlowNameFormatService; @Component diff --git a/redbeams/src/main/java/com/sequenceiq/redbeams/rotation/RedbeamsSecretRotationInformation.java b/redbeams/src/main/java/com/sequenceiq/redbeams/rotation/RedbeamsSecretRotationInformation.java index 43d7223965e..8d7458a0840 100644 --- a/redbeams/src/main/java/com/sequenceiq/redbeams/rotation/RedbeamsSecretRotationInformation.java +++ b/redbeams/src/main/java/com/sequenceiq/redbeams/rotation/RedbeamsSecretRotationInformation.java @@ -2,8 +2,8 @@ import org.springframework.stereotype.Component; -import com.sequenceiq.cloudbreak.rotation.secret.SecretType; -import com.sequenceiq.cloudbreak.rotation.secret.application.ApplicationSecretRotationInformation; +import com.sequenceiq.cloudbreak.rotation.SecretType; +import com.sequenceiq.cloudbreak.rotation.config.ApplicationSecretRotationInformation; @Component public class RedbeamsSecretRotationInformation implements ApplicationSecretRotationInformation { diff --git a/redbeams/src/main/java/com/sequenceiq/redbeams/rotation/RootPasswordRotationExecutor.java b/redbeams/src/main/java/com/sequenceiq/redbeams/rotation/RootPasswordRotationExecutor.java index 94506921dce..5420bf757ef 100644 --- a/redbeams/src/main/java/com/sequenceiq/redbeams/rotation/RootPasswordRotationExecutor.java +++ b/redbeams/src/main/java/com/sequenceiq/redbeams/rotation/RootPasswordRotationExecutor.java @@ -19,10 +19,10 @@ import com.sequenceiq.cloudbreak.cloud.model.DatabaseStack; import com.sequenceiq.cloudbreak.cloud.model.ExternalDatabaseStatus; import com.sequenceiq.cloudbreak.cloud.model.Location; -import com.sequenceiq.cloudbreak.rotation.secret.AbstractRotationExecutor; -import com.sequenceiq.cloudbreak.rotation.secret.RotationContext; -import com.sequenceiq.cloudbreak.rotation.secret.SecretRotationException; -import com.sequenceiq.cloudbreak.rotation.secret.step.SecretRotationStep; +import com.sequenceiq.cloudbreak.rotation.SecretRotationStep; +import com.sequenceiq.cloudbreak.rotation.common.RotationContext; +import com.sequenceiq.cloudbreak.rotation.common.SecretRotationException; +import com.sequenceiq.cloudbreak.rotation.executor.AbstractRotationExecutor; import com.sequenceiq.cloudbreak.service.secret.domain.RotationSecret; import com.sequenceiq.cloudbreak.service.secret.service.SecretService; import com.sequenceiq.redbeams.converter.cloud.CredentialToCloudCredentialConverter; diff --git a/redbeams/src/main/java/com/sequenceiq/redbeams/rotation/context/provider/ExternalDatabaseRootPasswordRotationContextProvider.java b/redbeams/src/main/java/com/sequenceiq/redbeams/rotation/context/provider/ExternalDatabaseRootPasswordRotationContextProvider.java index 02471ba4d19..27e1222befa 100644 --- a/redbeams/src/main/java/com/sequenceiq/redbeams/rotation/context/provider/ExternalDatabaseRootPasswordRotationContextProvider.java +++ b/redbeams/src/main/java/com/sequenceiq/redbeams/rotation/context/provider/ExternalDatabaseRootPasswordRotationContextProvider.java @@ -9,11 +9,11 @@ import org.springframework.stereotype.Component; import com.sequenceiq.cloudbreak.common.mappable.CloudPlatform; -import com.sequenceiq.cloudbreak.rotation.secret.RotationContext; -import com.sequenceiq.cloudbreak.rotation.secret.RotationContextProvider; -import com.sequenceiq.cloudbreak.rotation.secret.SecretType; -import com.sequenceiq.cloudbreak.rotation.secret.step.CommonSecretRotationStep; -import com.sequenceiq.cloudbreak.rotation.secret.step.SecretRotationStep; +import com.sequenceiq.cloudbreak.rotation.CommonSecretRotationStep; +import com.sequenceiq.cloudbreak.rotation.SecretRotationStep; +import com.sequenceiq.cloudbreak.rotation.SecretType; +import com.sequenceiq.cloudbreak.rotation.common.RotationContext; +import com.sequenceiq.cloudbreak.rotation.common.RotationContextProvider; import com.sequenceiq.cloudbreak.rotation.secret.vault.VaultRotationContext; import com.sequenceiq.redbeams.domain.DatabaseServerConfig; import com.sequenceiq.redbeams.domain.stack.DBStack; diff --git a/redbeams/src/main/java/com/sequenceiq/redbeams/service/rotation/RedbeamsRotationService.java b/redbeams/src/main/java/com/sequenceiq/redbeams/service/rotation/RedbeamsRotationService.java index e0cf4c73dd2..06aaa3c3503 100644 --- a/redbeams/src/main/java/com/sequenceiq/redbeams/service/rotation/RedbeamsRotationService.java +++ b/redbeams/src/main/java/com/sequenceiq/redbeams/service/rotation/RedbeamsRotationService.java @@ -9,10 +9,10 @@ import com.sequenceiq.cloudbreak.auth.altus.EntitlementService; import com.sequenceiq.cloudbreak.auth.crn.Crn; import com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException; -import com.sequenceiq.cloudbreak.rotation.secret.RotationFlowExecutionType; -import com.sequenceiq.cloudbreak.rotation.secret.SecretType; +import com.sequenceiq.cloudbreak.rotation.RotationFlowExecutionType; +import com.sequenceiq.cloudbreak.rotation.SecretType; +import com.sequenceiq.cloudbreak.rotation.service.SecretRotationValidator; import com.sequenceiq.flow.api.model.FlowIdentifier; -import com.sequenceiq.flow.rotation.service.SecretRotationValidator; import com.sequenceiq.redbeams.flow.RedbeamsFlowManager; import com.sequenceiq.redbeams.rotation.RedbeamsSecretType; import com.sequenceiq.redbeams.service.stack.DBStackService; diff --git a/redbeams/src/test/java/com/sequenceiq/redbeams/flow/RedbeamsFlowManagerTest.java b/redbeams/src/test/java/com/sequenceiq/redbeams/flow/RedbeamsFlowManagerTest.java index 9309a8b857d..efd99a8c95e 100644 --- a/redbeams/src/test/java/com/sequenceiq/redbeams/flow/RedbeamsFlowManagerTest.java +++ b/redbeams/src/test/java/com/sequenceiq/redbeams/flow/RedbeamsFlowManagerTest.java @@ -24,12 +24,12 @@ import com.sequenceiq.cloudbreak.eventbus.Event; import com.sequenceiq.cloudbreak.eventbus.EventBus; import com.sequenceiq.cloudbreak.eventbus.Promise; +import com.sequenceiq.cloudbreak.rotation.flow.chain.SecretRotationFlowChainTriggerEvent; import com.sequenceiq.flow.api.model.FlowIdentifier; import com.sequenceiq.flow.api.model.FlowType; import com.sequenceiq.flow.core.model.FlowAcceptResult; import com.sequenceiq.flow.event.EventSelectorUtil; import com.sequenceiq.flow.reactor.ErrorHandlerAwareReactorEventFactory; -import com.sequenceiq.flow.rotation.chain.SecretRotationFlowChainTriggerEvent; import com.sequenceiq.flow.service.FlowNameFormatService; @ExtendWith(MockitoExtension.class) diff --git a/redbeams/src/test/java/com/sequenceiq/redbeams/rotation/context/provider/ExternalDatabaseRootPasswordRotationContextProviderTest.java b/redbeams/src/test/java/com/sequenceiq/redbeams/rotation/context/provider/ExternalDatabaseRootPasswordRotationContextProviderTest.java index 433fc031818..fedae272545 100644 --- a/redbeams/src/test/java/com/sequenceiq/redbeams/rotation/context/provider/ExternalDatabaseRootPasswordRotationContextProviderTest.java +++ b/redbeams/src/test/java/com/sequenceiq/redbeams/rotation/context/provider/ExternalDatabaseRootPasswordRotationContextProviderTest.java @@ -16,9 +16,9 @@ import org.mockito.junit.jupiter.MockitoExtension; import com.sequenceiq.cloudbreak.common.mappable.CloudPlatform; -import com.sequenceiq.cloudbreak.rotation.secret.RotationContext; -import com.sequenceiq.cloudbreak.rotation.secret.step.CommonSecretRotationStep; -import com.sequenceiq.cloudbreak.rotation.secret.step.SecretRotationStep; +import com.sequenceiq.cloudbreak.rotation.CommonSecretRotationStep; +import com.sequenceiq.cloudbreak.rotation.SecretRotationStep; +import com.sequenceiq.cloudbreak.rotation.common.RotationContext; import com.sequenceiq.cloudbreak.rotation.secret.vault.VaultRotationContext; import com.sequenceiq.redbeams.domain.DatabaseServerConfig; import com.sequenceiq.redbeams.domain.stack.DBStack; diff --git a/redbeams/src/test/java/com/sequenceiq/redbeams/rotation/context/provider/RootPasswordRotationExecutorTest.java b/redbeams/src/test/java/com/sequenceiq/redbeams/rotation/context/provider/RootPasswordRotationExecutorTest.java index 47966f5093a..3d9e88250c4 100644 --- a/redbeams/src/test/java/com/sequenceiq/redbeams/rotation/context/provider/RootPasswordRotationExecutorTest.java +++ b/redbeams/src/test/java/com/sequenceiq/redbeams/rotation/context/provider/RootPasswordRotationExecutorTest.java @@ -14,7 +14,6 @@ import java.util.HashMap; import java.util.Optional; -import org.apache.commons.lang3.reflect.FieldUtils; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -30,9 +29,9 @@ import com.sequenceiq.cloudbreak.cloud.model.CloudCredential; import com.sequenceiq.cloudbreak.cloud.model.DatabaseStack; import com.sequenceiq.cloudbreak.cloud.model.ExternalDatabaseStatus; -import com.sequenceiq.cloudbreak.rotation.secret.RotationContext; -import com.sequenceiq.cloudbreak.rotation.secret.SecretRotationException; -import com.sequenceiq.cloudbreak.rotation.secret.SecretRotationProgressService; +import com.sequenceiq.cloudbreak.rotation.common.RotationContext; +import com.sequenceiq.cloudbreak.rotation.common.SecretRotationException; +import com.sequenceiq.cloudbreak.rotation.service.progress.SecretRotationStepProgressService; import com.sequenceiq.cloudbreak.service.secret.domain.RotationSecret; import com.sequenceiq.cloudbreak.service.secret.service.SecretService; import com.sequenceiq.redbeams.converter.cloud.CredentialToCloudCredentialConverter; @@ -84,14 +83,13 @@ class RootPasswordRotationExecutorTest { private DatabaseServerConfigService databaseServerConfigService; @Mock - private SecretRotationProgressService secretRotationProgressService; + private SecretRotationStepProgressService secretRotationProgressService; @InjectMocks private RootPasswordRotationExecutor underTest; @BeforeEach - void mockProgressService() throws IllegalAccessException { - FieldUtils.writeField(underTest, "secretRotationProgressService", Optional.of(secretRotationProgressService), true); + void mockProgressService() { lenient().when(secretRotationProgressService.latestStep(any(), any(), any(), any())).thenReturn(Optional.empty()); } diff --git a/redbeams/src/test/java/com/sequenceiq/redbeams/service/rotation/RedbeamsRotationServiceTest.java b/redbeams/src/test/java/com/sequenceiq/redbeams/service/rotation/RedbeamsRotationServiceTest.java index 01ef34fd012..d0a52269643 100644 --- a/redbeams/src/test/java/com/sequenceiq/redbeams/service/rotation/RedbeamsRotationServiceTest.java +++ b/redbeams/src/test/java/com/sequenceiq/redbeams/service/rotation/RedbeamsRotationServiceTest.java @@ -1,6 +1,6 @@ package com.sequenceiq.redbeams.service.rotation; -import static com.sequenceiq.cloudbreak.rotation.secret.RotationFlowExecutionType.ROTATE; +import static com.sequenceiq.cloudbreak.rotation.RotationFlowExecutionType.ROTATE; import static com.sequenceiq.redbeams.rotation.RedbeamsSecretType.REDBEAMS_EXTERNAL_DATABASE_ROOT_PASSWORD; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; @@ -23,7 +23,7 @@ import com.sequenceiq.cloudbreak.auth.altus.EntitlementService; import com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException; -import com.sequenceiq.flow.rotation.service.SecretRotationValidator; +import com.sequenceiq.cloudbreak.rotation.service.SecretRotationValidator; import com.sequenceiq.redbeams.flow.RedbeamsFlowManager; import com.sequenceiq.redbeams.service.stack.DBStackService; diff --git a/secret-rotation-api/build.gradle b/secret-rotation-api/build.gradle new file mode 100644 index 00000000000..a0e2bf42a4f --- /dev/null +++ b/secret-rotation-api/build.gradle @@ -0,0 +1,53 @@ +buildscript { + repositories { + maven { url = "$repoUrl" } + maven { url = "$springRepoUrl" } + mavenCentral() + } + dependencies { + classpath "org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}" + } +} + +plugins { + id "java-library" +} + +apply plugin: 'java' +apply plugin: 'io.spring.dependency-management' + +jar { + archiveBaseName = 'secret-rotation-api' + archiveFileName = 'secret-rotation-api.jar' +} + +dependencies { + implementation project(':common') + implementation group: 'org.slf4j', name: 'slf4j-api', version: slf4jApiVersion + implementation group: 'org.apache.commons', name: 'commons-lang3', version: apacheCommonsLangVersion + implementation group: 'org.glassfish.jersey.core', name: 'jersey-client', version: jerseyCoreVersion + implementation group: 'io.swagger', name: 'swagger-annotations', version: swaggerVersion + implementation group: 'com.google.guava', name: 'guava', version: guavaVersion + + testImplementation group: 'org.mockito', name: 'mockito-core', version: mockitoVersion + testImplementation group: 'org.springframework.boot', name: 'spring-boot-starter-test', version: springBootVersion + + implementation group: 'org.springframework.boot', name: 'spring-boot-starter', version: springBootVersion + testImplementation group: 'org.springframework.boot', name: 'spring-boot-starter-test', version: springBootVersion + +} + +task testJar(type: Jar, dependsOn: testClasses) { + archiveBaseName = "test-${project.archivesBaseName}" + archiveClassifier = 'test' + from sourceSets.test.output + from sourceSets.main.output +} + +configurations { + tests +} + +artifacts { + tests testJar +} diff --git a/common/src/main/java/com/sequenceiq/cloudbreak/rotation/secret/step/CommonSecretRotationStep.java b/secret-rotation-api/src/main/java/com/sequenceiq/cloudbreak/rotation/CommonSecretRotationStep.java similarity index 69% rename from common/src/main/java/com/sequenceiq/cloudbreak/rotation/secret/step/CommonSecretRotationStep.java rename to secret-rotation-api/src/main/java/com/sequenceiq/cloudbreak/rotation/CommonSecretRotationStep.java index c1b1cb5649f..f335552b007 100644 --- a/common/src/main/java/com/sequenceiq/cloudbreak/rotation/secret/step/CommonSecretRotationStep.java +++ b/secret-rotation-api/src/main/java/com/sequenceiq/cloudbreak/rotation/CommonSecretRotationStep.java @@ -1,10 +1,10 @@ -package com.sequenceiq.cloudbreak.rotation.secret.step; +package com.sequenceiq.cloudbreak.rotation; public enum CommonSecretRotationStep implements SecretRotationStep { VAULT, CUSTOM_JOB, REDBEAMS_ROTATE_POLLING, CLOUDBREAK_ROTATE_POLLING, - SERVICE_CONFIG, + SALTBOOT_CONFIG, USER_DATA } diff --git a/common/src/main/java/com/sequenceiq/cloudbreak/rotation/secret/RotationFlowExecutionType.java b/secret-rotation-api/src/main/java/com/sequenceiq/cloudbreak/rotation/RotationFlowExecutionType.java similarity index 61% rename from common/src/main/java/com/sequenceiq/cloudbreak/rotation/secret/RotationFlowExecutionType.java rename to secret-rotation-api/src/main/java/com/sequenceiq/cloudbreak/rotation/RotationFlowExecutionType.java index b763ae15642..53b6b62fcd2 100644 --- a/common/src/main/java/com/sequenceiq/cloudbreak/rotation/secret/RotationFlowExecutionType.java +++ b/secret-rotation-api/src/main/java/com/sequenceiq/cloudbreak/rotation/RotationFlowExecutionType.java @@ -1,4 +1,4 @@ -package com.sequenceiq.cloudbreak.rotation.secret; +package com.sequenceiq.cloudbreak.rotation; public enum RotationFlowExecutionType { ROLLBACK, diff --git a/secret-rotation-api/src/main/java/com/sequenceiq/cloudbreak/rotation/SecretRotationStep.java b/secret-rotation-api/src/main/java/com/sequenceiq/cloudbreak/rotation/SecretRotationStep.java new file mode 100644 index 00000000000..0f50cb77170 --- /dev/null +++ b/secret-rotation-api/src/main/java/com/sequenceiq/cloudbreak/rotation/SecretRotationStep.java @@ -0,0 +1,5 @@ +package com.sequenceiq.cloudbreak.rotation; + +public interface SecretRotationStep { + +} diff --git a/secret-rotation-api/src/main/java/com/sequenceiq/cloudbreak/rotation/SecretType.java b/secret-rotation-api/src/main/java/com/sequenceiq/cloudbreak/rotation/SecretType.java new file mode 100644 index 00000000000..a198c3fce93 --- /dev/null +++ b/secret-rotation-api/src/main/java/com/sequenceiq/cloudbreak/rotation/SecretType.java @@ -0,0 +1,7 @@ +package com.sequenceiq.cloudbreak.rotation; + +import java.util.List; + +public interface SecretType { + List getSteps(); +} diff --git a/common/src/main/java/com/sequenceiq/cloudbreak/rotation/secret/README.md b/secret-rotation/README.md similarity index 100% rename from common/src/main/java/com/sequenceiq/cloudbreak/rotation/secret/README.md rename to secret-rotation/README.md diff --git a/secret-rotation/build.gradle b/secret-rotation/build.gradle new file mode 100644 index 00000000000..d0d6c5f2849 --- /dev/null +++ b/secret-rotation/build.gradle @@ -0,0 +1,58 @@ +buildscript { + repositories { + maven { url = "$repoUrl" } + maven { url = "$springRepoUrl" } + mavenCentral() + } + dependencies { + classpath "org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}" + } +} + +plugins { + id "java-library" +} + +apply plugin: 'java' +apply plugin: 'io.spring.dependency-management' + +jar { + archiveBaseName = 'secret-rotation' + archiveFileName = 'secret-rotation.jar' +} + +dependencies { + implementation project(':common') + implementation project(':secret-engine') + implementation project(':secret-rotation-api') + implementation project(':usage-collection') + implementation project(":flow") + implementation group: 'org.slf4j', name: 'slf4j-api', version: slf4jApiVersion + implementation group: 'org.apache.commons', name: 'commons-lang3', version: apacheCommonsLangVersion + implementation group: 'org.glassfish.jersey.core', name: 'jersey-client', version: jerseyCoreVersion + implementation group: 'io.swagger', name: 'swagger-annotations', version: swaggerVersion + implementation group: 'com.google.guava', name: 'guava', version: guavaVersion + implementation project(path: ':secret-rotation-api') + + testImplementation group: 'org.mockito', name: 'mockito-core', version: mockitoVersion + testImplementation group: 'org.springframework.boot', name: 'spring-boot-starter-test', version: springBootVersion + + implementation group: 'org.springframework.boot', name: 'spring-boot-starter', version: springBootVersion + testImplementation group: 'org.springframework.boot', name: 'spring-boot-starter-test', version: springBootVersion + +} + +task testJar(type: Jar, dependsOn: testClasses) { + archiveBaseName = "test-${project.archivesBaseName}" + archiveClassifier = 'test' + from sourceSets.test.output + from sourceSets.main.output +} + +configurations { + tests +} + +artifacts { + tests testJar +} diff --git a/common/src/main/java/com/sequenceiq/cloudbreak/rotation/secret/RotationContext.java b/secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/common/RotationContext.java similarity index 82% rename from common/src/main/java/com/sequenceiq/cloudbreak/rotation/secret/RotationContext.java rename to secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/common/RotationContext.java index 68a2c71aa25..523c89e2727 100644 --- a/common/src/main/java/com/sequenceiq/cloudbreak/rotation/secret/RotationContext.java +++ b/secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/common/RotationContext.java @@ -1,4 +1,4 @@ -package com.sequenceiq.cloudbreak.rotation.secret; +package com.sequenceiq.cloudbreak.rotation.common; public class RotationContext { diff --git a/common/src/main/java/com/sequenceiq/cloudbreak/rotation/secret/RotationContextProvider.java b/secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/common/RotationContextProvider.java similarity index 53% rename from common/src/main/java/com/sequenceiq/cloudbreak/rotation/secret/RotationContextProvider.java rename to secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/common/RotationContextProvider.java index 5c1c8b91bc5..3cc4509ece1 100644 --- a/common/src/main/java/com/sequenceiq/cloudbreak/rotation/secret/RotationContextProvider.java +++ b/secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/common/RotationContextProvider.java @@ -1,8 +1,9 @@ -package com.sequenceiq.cloudbreak.rotation.secret; +package com.sequenceiq.cloudbreak.rotation.common; import java.util.Map; -import com.sequenceiq.cloudbreak.rotation.secret.step.SecretRotationStep; +import com.sequenceiq.cloudbreak.rotation.SecretRotationStep; +import com.sequenceiq.cloudbreak.rotation.SecretType; public interface RotationContextProvider { diff --git a/common/src/main/java/com/sequenceiq/cloudbreak/rotation/secret/RotationExecutor.java b/secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/common/RotationExecutor.java similarity index 77% rename from common/src/main/java/com/sequenceiq/cloudbreak/rotation/secret/RotationExecutor.java rename to secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/common/RotationExecutor.java index 42ae0072c68..15f07bd54b5 100644 --- a/common/src/main/java/com/sequenceiq/cloudbreak/rotation/secret/RotationExecutor.java +++ b/secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/common/RotationExecutor.java @@ -1,6 +1,6 @@ -package com.sequenceiq.cloudbreak.rotation.secret; +package com.sequenceiq.cloudbreak.rotation.common; -import com.sequenceiq.cloudbreak.rotation.secret.step.SecretRotationStep; +import com.sequenceiq.cloudbreak.rotation.SecretRotationStep; public interface RotationExecutor { diff --git a/common/src/main/java/com/sequenceiq/cloudbreak/rotation/secret/SecretRotationException.java b/secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/common/SecretRotationException.java similarity index 89% rename from common/src/main/java/com/sequenceiq/cloudbreak/rotation/secret/SecretRotationException.java rename to secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/common/SecretRotationException.java index ae2e42d0f75..98b4a57677d 100644 --- a/common/src/main/java/com/sequenceiq/cloudbreak/rotation/secret/SecretRotationException.java +++ b/secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/common/SecretRotationException.java @@ -1,6 +1,6 @@ -package com.sequenceiq.cloudbreak.rotation.secret; +package com.sequenceiq.cloudbreak.rotation.common; -import com.sequenceiq.cloudbreak.rotation.secret.step.SecretRotationStep; +import com.sequenceiq.cloudbreak.rotation.SecretRotationStep; public class SecretRotationException extends RuntimeException { diff --git a/secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/config/ApplicationSecretRotationInformation.java b/secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/config/ApplicationSecretRotationInformation.java new file mode 100644 index 00000000000..76894aaa701 --- /dev/null +++ b/secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/config/ApplicationSecretRotationInformation.java @@ -0,0 +1,9 @@ +package com.sequenceiq.cloudbreak.rotation.config; + +import com.sequenceiq.cloudbreak.rotation.SecretType; + +public interface ApplicationSecretRotationInformation { + + Class supportedSecretType(); + +} diff --git a/secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/config/RotationSchemaLocationProvider.java b/secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/config/RotationSchemaLocationProvider.java new file mode 100644 index 00000000000..0b1479ecee9 --- /dev/null +++ b/secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/config/RotationSchemaLocationProvider.java @@ -0,0 +1,16 @@ +package com.sequenceiq.cloudbreak.rotation.config; + +import java.util.Optional; + +import org.springframework.stereotype.Component; + +import com.sequenceiq.cloudbreak.common.dbmigration.SchemaLocationProvider; + +@Component +public class RotationSchemaLocationProvider implements SchemaLocationProvider { + + @Override + public Optional pendingSubfolder() { + return Optional.of("rotation"); + } +} diff --git a/flow/src/main/java/com/sequenceiq/flow/rotation/service/SecretRotationConfig.java b/secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/config/SecretRotationConfig.java similarity index 84% rename from flow/src/main/java/com/sequenceiq/flow/rotation/service/SecretRotationConfig.java rename to secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/config/SecretRotationConfig.java index db9b44589f8..a87f9dedfd6 100644 --- a/flow/src/main/java/com/sequenceiq/flow/rotation/service/SecretRotationConfig.java +++ b/secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/config/SecretRotationConfig.java @@ -1,4 +1,4 @@ -package com.sequenceiq.flow.rotation.service; +package com.sequenceiq.cloudbreak.rotation.config; import java.util.Arrays; import java.util.List; @@ -13,12 +13,11 @@ import org.springframework.context.annotation.Configuration; import com.google.common.collect.Maps; -import com.sequenceiq.cloudbreak.rotation.secret.AbstractRotationExecutor; -import com.sequenceiq.cloudbreak.rotation.secret.RotationContext; -import com.sequenceiq.cloudbreak.rotation.secret.RotationContextProvider; -import com.sequenceiq.cloudbreak.rotation.secret.SecretType; -import com.sequenceiq.cloudbreak.rotation.secret.application.ApplicationSecretRotationInformation; -import com.sequenceiq.cloudbreak.rotation.secret.step.SecretRotationStep; +import com.sequenceiq.cloudbreak.rotation.SecretRotationStep; +import com.sequenceiq.cloudbreak.rotation.SecretType; +import com.sequenceiq.cloudbreak.rotation.common.RotationContext; +import com.sequenceiq.cloudbreak.rotation.common.RotationContextProvider; +import com.sequenceiq.cloudbreak.rotation.executor.AbstractRotationExecutor; @Configuration public class SecretRotationConfig { diff --git a/flow/src/main/java/com/sequenceiq/flow/rotation/entity/RotationFlowExecutionTypeConverter.java b/secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/entity/RotationFlowExecutionTypeConverter.java similarity index 71% rename from flow/src/main/java/com/sequenceiq/flow/rotation/entity/RotationFlowExecutionTypeConverter.java rename to secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/entity/RotationFlowExecutionTypeConverter.java index d0e3acda3da..a572f1db7db 100644 --- a/flow/src/main/java/com/sequenceiq/flow/rotation/entity/RotationFlowExecutionTypeConverter.java +++ b/secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/entity/RotationFlowExecutionTypeConverter.java @@ -1,7 +1,7 @@ -package com.sequenceiq.flow.rotation.entity; +package com.sequenceiq.cloudbreak.rotation.entity; import com.sequenceiq.cloudbreak.converter.DefaultEnumConverter; -import com.sequenceiq.cloudbreak.rotation.secret.RotationFlowExecutionType; +import com.sequenceiq.cloudbreak.rotation.RotationFlowExecutionType; public class RotationFlowExecutionTypeConverter extends DefaultEnumConverter { diff --git a/flow/src/main/java/com/sequenceiq/flow/rotation/entity/SecretRotationStepConverter.java b/secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/entity/SecretRotationStepConverter.java similarity index 75% rename from flow/src/main/java/com/sequenceiq/flow/rotation/entity/SecretRotationStepConverter.java rename to secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/entity/SecretRotationStepConverter.java index b06edbb98cf..fce314e0e72 100644 --- a/flow/src/main/java/com/sequenceiq/flow/rotation/entity/SecretRotationStepConverter.java +++ b/secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/entity/SecretRotationStepConverter.java @@ -1,9 +1,9 @@ -package com.sequenceiq.flow.rotation.entity; +package com.sequenceiq.cloudbreak.rotation.entity; import javax.persistence.AttributeConverter; -import com.sequenceiq.cloudbreak.rotation.secret.serialization.SecretRotationEnumSerializationUtil; -import com.sequenceiq.cloudbreak.rotation.secret.step.SecretRotationStep; +import com.sequenceiq.cloudbreak.rotation.SecretRotationStep; +import com.sequenceiq.cloudbreak.rotation.serialization.SecretRotationEnumSerializationUtil; public class SecretRotationStepConverter implements AttributeConverter { @Override diff --git a/flow/src/main/java/com/sequenceiq/flow/rotation/entity/SecretRotationStepProgress.java b/secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/entity/SecretRotationStepProgress.java similarity index 91% rename from flow/src/main/java/com/sequenceiq/flow/rotation/entity/SecretRotationStepProgress.java rename to secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/entity/SecretRotationStepProgress.java index e9190509d7a..e57f205ce8d 100644 --- a/flow/src/main/java/com/sequenceiq/flow/rotation/entity/SecretRotationStepProgress.java +++ b/secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/entity/SecretRotationStepProgress.java @@ -1,4 +1,4 @@ -package com.sequenceiq.flow.rotation.entity; +package com.sequenceiq.cloudbreak.rotation.entity; import javax.persistence.Convert; import javax.persistence.Entity; @@ -7,9 +7,9 @@ import javax.persistence.Id; import javax.persistence.SequenceGenerator; -import com.sequenceiq.cloudbreak.rotation.secret.RotationFlowExecutionType; -import com.sequenceiq.cloudbreak.rotation.secret.SecretType; -import com.sequenceiq.cloudbreak.rotation.secret.step.SecretRotationStep; +import com.sequenceiq.cloudbreak.rotation.RotationFlowExecutionType; +import com.sequenceiq.cloudbreak.rotation.SecretRotationStep; +import com.sequenceiq.cloudbreak.rotation.SecretType; @Entity public class SecretRotationStepProgress { diff --git a/flow/src/main/java/com/sequenceiq/flow/rotation/entity/SecretTypeConverter.java b/secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/entity/SecretTypeConverter.java similarity index 75% rename from flow/src/main/java/com/sequenceiq/flow/rotation/entity/SecretTypeConverter.java rename to secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/entity/SecretTypeConverter.java index 81f825b0fdc..e232ccbaa2d 100644 --- a/flow/src/main/java/com/sequenceiq/flow/rotation/entity/SecretTypeConverter.java +++ b/secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/entity/SecretTypeConverter.java @@ -1,9 +1,9 @@ -package com.sequenceiq.flow.rotation.entity; +package com.sequenceiq.cloudbreak.rotation.entity; import javax.persistence.AttributeConverter; -import com.sequenceiq.cloudbreak.rotation.secret.SecretType; -import com.sequenceiq.cloudbreak.rotation.secret.serialization.SecretRotationEnumSerializationUtil; +import com.sequenceiq.cloudbreak.rotation.SecretType; +import com.sequenceiq.cloudbreak.rotation.serialization.SecretRotationEnumSerializationUtil; public class SecretTypeConverter implements AttributeConverter { @Override diff --git a/common/src/main/java/com/sequenceiq/cloudbreak/rotation/secret/AbstractRotationExecutor.java b/secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/executor/AbstractRotationExecutor.java similarity index 70% rename from common/src/main/java/com/sequenceiq/cloudbreak/rotation/secret/AbstractRotationExecutor.java rename to secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/executor/AbstractRotationExecutor.java index aca16c171cf..5e785fd05fd 100644 --- a/common/src/main/java/com/sequenceiq/cloudbreak/rotation/secret/AbstractRotationExecutor.java +++ b/secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/executor/AbstractRotationExecutor.java @@ -1,4 +1,4 @@ -package com.sequenceiq.cloudbreak.rotation.secret; +package com.sequenceiq.cloudbreak.rotation.executor; import java.util.Optional; import java.util.function.Supplier; @@ -8,6 +8,13 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import com.sequenceiq.cloudbreak.rotation.RotationFlowExecutionType; +import com.sequenceiq.cloudbreak.rotation.SecretType; +import com.sequenceiq.cloudbreak.rotation.common.RotationContext; +import com.sequenceiq.cloudbreak.rotation.common.RotationExecutor; +import com.sequenceiq.cloudbreak.rotation.common.SecretRotationException; +import com.sequenceiq.cloudbreak.rotation.entity.SecretRotationStepProgress; +import com.sequenceiq.cloudbreak.rotation.service.progress.SecretRotationStepProgressService; import com.sequenceiq.cloudbreak.util.CheckedConsumer; public abstract class AbstractRotationExecutor implements RotationExecutor { @@ -15,7 +22,7 @@ public abstract class AbstractRotationExecutor implem private static final Logger LOGGER = LoggerFactory.getLogger(AbstractRotationExecutor.class); @Inject - private Optional secretRotationProgressService; + private SecretRotationStepProgressService progressService; public final void executeRotate(RotationContext context, SecretType secretType) { invokeRotationPhaseWithProgressCheck(context, secretType, RotationFlowExecutionType.ROTATE, this::rotate, @@ -49,20 +56,18 @@ private void logAndThrow(Exception e, String errorMessage) { private void invokeRotationPhaseWithProgressCheck(RotationContext context, SecretType secretType, RotationFlowExecutionType executionType, CheckedConsumer rotationPhaseLogic, Supplier errorMessageSupplier) { - secretRotationProgressService.ifPresentOrElse(progressService -> { - Optional latestStepProgress = progressService.latestStep(context.getResourceCrn(), secretType, getType(), executionType); - if (latestStepProgress.isEmpty() || !progressService.isFinished(latestStepProgress.get())) { - try { - rotationPhaseLogic.accept(castContext(context)); - latestStepProgress.ifPresent(progressService::finished); - } catch (Exception e) { - latestStepProgress.ifPresent(progressService::finished); - logAndThrow(e, errorMessageSupplier.get()); - } - } else { - LOGGER.info("{} is already finished for {} step regarding {} secret, thus skipping it.", executionType, getType(), secretType); + Optional latestStepProgress = progressService.latestStep(context.getResourceCrn(), secretType, getType(), executionType); + if (latestStepProgress.isEmpty() || latestStepProgress.get().getFinished() == null) { + try { + rotationPhaseLogic.accept(castContext(context)); + } catch (Exception e) { + logAndThrow(e, errorMessageSupplier.get()); + } finally { + latestStepProgress.ifPresent(progressService::finished); } - }, () -> invokeRotationPhase(context, rotationPhaseLogic, errorMessageSupplier)); + } else { + LOGGER.info("{} is already finished for {} step regarding {} secret, thus skipping it.", executionType, getType(), secretType); + } } private void invokeRotationPhase(RotationContext context, CheckedConsumer rotationPhaseLogic, Supplier errorMessageSupplier) { diff --git a/flow/src/main/java/com/sequenceiq/flow/rotation/chain/SecretRotationFlowChainTriggerEvent.java b/secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/flow/chain/SecretRotationFlowChainTriggerEvent.java similarity index 84% rename from flow/src/main/java/com/sequenceiq/flow/rotation/chain/SecretRotationFlowChainTriggerEvent.java rename to secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/flow/chain/SecretRotationFlowChainTriggerEvent.java index 29ed2d2f029..0993e2ab935 100644 --- a/flow/src/main/java/com/sequenceiq/flow/rotation/chain/SecretRotationFlowChainTriggerEvent.java +++ b/secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/flow/chain/SecretRotationFlowChainTriggerEvent.java @@ -1,4 +1,4 @@ -package com.sequenceiq.flow.rotation.chain; +package com.sequenceiq.cloudbreak.rotation.flow.chain; import java.util.List; import java.util.Objects; @@ -7,11 +7,11 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.fasterxml.jackson.databind.annotation.JsonSerialize; -import com.sequenceiq.cloudbreak.rotation.secret.RotationFlowExecutionType; -import com.sequenceiq.cloudbreak.rotation.secret.SecretType; +import com.sequenceiq.cloudbreak.rotation.RotationFlowExecutionType; +import com.sequenceiq.cloudbreak.rotation.SecretType; +import com.sequenceiq.cloudbreak.rotation.flow.serialization.SecretTypeListDeserializer; +import com.sequenceiq.cloudbreak.rotation.flow.serialization.SecretTypeListSerializer; import com.sequenceiq.flow.reactor.api.event.BaseFlowEvent; -import com.sequenceiq.flow.rotation.serialization.SecretTypeListDeserializer; -import com.sequenceiq.flow.rotation.serialization.SecretTypeListSerializer; public class SecretRotationFlowChainTriggerEvent extends BaseFlowEvent { diff --git a/flow/src/main/java/com/sequenceiq/flow/rotation/chain/SecretRotationFlowEventChainFactory.java b/secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/flow/chain/SecretRotationFlowEventChainFactory.java similarity index 84% rename from flow/src/main/java/com/sequenceiq/flow/rotation/chain/SecretRotationFlowEventChainFactory.java rename to secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/flow/chain/SecretRotationFlowEventChainFactory.java index 86426b9fc37..44831ca99e4 100644 --- a/flow/src/main/java/com/sequenceiq/flow/rotation/chain/SecretRotationFlowEventChainFactory.java +++ b/secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/flow/chain/SecretRotationFlowEventChainFactory.java @@ -1,4 +1,4 @@ -package com.sequenceiq.flow.rotation.chain; +package com.sequenceiq.cloudbreak.rotation.flow.chain; import java.util.Queue; import java.util.concurrent.ConcurrentLinkedQueue; @@ -6,11 +6,11 @@ import org.springframework.stereotype.Component; import com.sequenceiq.cloudbreak.common.event.Selectable; +import com.sequenceiq.cloudbreak.rotation.flow.rotation.event.SecretRotationTriggerEvent; +import com.sequenceiq.cloudbreak.rotation.flow.status.event.RotationStatusChangeTriggerEvent; import com.sequenceiq.flow.core.chain.FlowEventChainFactory; import com.sequenceiq.flow.core.chain.config.FlowTriggerEventQueue; import com.sequenceiq.flow.event.EventSelectorUtil; -import com.sequenceiq.flow.rotation.event.SecretRotationTriggerEvent; -import com.sequenceiq.flow.rotation.status.event.RotationStatusChangeTriggerEvent; @Component public class SecretRotationFlowEventChainFactory implements FlowEventChainFactory { diff --git a/flow/src/main/java/com/sequenceiq/flow/rotation/RotationFlowContext.java b/secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/flow/rotation/RotationFlowContext.java similarity index 86% rename from flow/src/main/java/com/sequenceiq/flow/rotation/RotationFlowContext.java rename to secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/flow/rotation/RotationFlowContext.java index 1953048d146..bdc8b563f07 100644 --- a/flow/src/main/java/com/sequenceiq/flow/rotation/RotationFlowContext.java +++ b/secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/flow/rotation/RotationFlowContext.java @@ -1,12 +1,12 @@ -package com.sequenceiq.flow.rotation; +package com.sequenceiq.cloudbreak.rotation.flow.rotation; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; -import com.sequenceiq.cloudbreak.rotation.secret.RotationFlowExecutionType; -import com.sequenceiq.cloudbreak.rotation.secret.SecretType; +import com.sequenceiq.cloudbreak.rotation.RotationFlowExecutionType; +import com.sequenceiq.cloudbreak.rotation.SecretType; +import com.sequenceiq.cloudbreak.rotation.flow.rotation.event.RotationEvent; import com.sequenceiq.flow.core.CommonContext; import com.sequenceiq.flow.core.FlowParameters; -import com.sequenceiq.flow.rotation.event.RotationEvent; public class RotationFlowContext extends CommonContext { diff --git a/flow/src/main/java/com/sequenceiq/flow/rotation/SecretRotationActions.java b/secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/flow/rotation/SecretRotationActions.java similarity index 82% rename from flow/src/main/java/com/sequenceiq/flow/rotation/SecretRotationActions.java rename to secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/flow/rotation/SecretRotationActions.java index 31d317f2d28..05b88377420 100644 --- a/flow/src/main/java/com/sequenceiq/flow/rotation/SecretRotationActions.java +++ b/secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/flow/rotation/SecretRotationActions.java @@ -1,6 +1,6 @@ -package com.sequenceiq.flow.rotation; +package com.sequenceiq.cloudbreak.rotation.flow.rotation; -import static com.sequenceiq.cloudbreak.rotation.secret.SecretRotationException.getFailedStepFromException; +import static com.sequenceiq.cloudbreak.rotation.common.SecretRotationException.getFailedStepFromException; import java.util.Map; import java.util.Optional; @@ -14,27 +14,27 @@ import org.springframework.statemachine.StateContext; import org.springframework.statemachine.action.Action; -import com.sequenceiq.cloudbreak.rotation.secret.RotationFlowExecutionType; -import com.sequenceiq.cloudbreak.rotation.secret.SecretRotationException; -import com.sequenceiq.cloudbreak.rotation.secret.SecretRotationProgressService; -import com.sequenceiq.cloudbreak.rotation.secret.step.SecretRotationStep; -import com.sequenceiq.cloudbreak.rotation.secret.usage.SecretRotationUsageProcessor; +import com.sequenceiq.cloudbreak.rotation.RotationFlowExecutionType; +import com.sequenceiq.cloudbreak.rotation.SecretRotationStep; +import com.sequenceiq.cloudbreak.rotation.common.SecretRotationException; +import com.sequenceiq.cloudbreak.rotation.flow.rotation.config.SecretRotationEvent; +import com.sequenceiq.cloudbreak.rotation.flow.rotation.config.SecretRotationState; +import com.sequenceiq.cloudbreak.rotation.flow.rotation.event.ExecuteRotationFailedEvent; +import com.sequenceiq.cloudbreak.rotation.flow.rotation.event.ExecuteRotationFinishedEvent; +import com.sequenceiq.cloudbreak.rotation.flow.rotation.event.ExecuteRotationTriggerEvent; +import com.sequenceiq.cloudbreak.rotation.flow.rotation.event.FinalizeRotationTriggerEvent; +import com.sequenceiq.cloudbreak.rotation.flow.rotation.event.PreValidateRotationFinishedEvent; +import com.sequenceiq.cloudbreak.rotation.flow.rotation.event.PreValidateRotationTriggerEvent; +import com.sequenceiq.cloudbreak.rotation.flow.rotation.event.RollbackRotationTriggerEvent; +import com.sequenceiq.cloudbreak.rotation.flow.rotation.event.RotationEvent; +import com.sequenceiq.cloudbreak.rotation.flow.rotation.event.RotationFailedEvent; +import com.sequenceiq.cloudbreak.rotation.flow.rotation.event.SecretRotationTriggerEvent; +import com.sequenceiq.cloudbreak.rotation.service.progress.SecretRotationStepProgressService; +import com.sequenceiq.cloudbreak.rotation.service.status.SecretRotationStatusService; +import com.sequenceiq.cloudbreak.rotation.service.usage.SecretRotationUsageService; import com.sequenceiq.flow.core.AbstractAction; import com.sequenceiq.flow.core.Flow; import com.sequenceiq.flow.core.FlowParameters; -import com.sequenceiq.flow.rotation.config.SecretRotationEvent; -import com.sequenceiq.flow.rotation.config.SecretRotationState; -import com.sequenceiq.flow.rotation.event.ExecuteRotationFailedEvent; -import com.sequenceiq.flow.rotation.event.ExecuteRotationFinishedEvent; -import com.sequenceiq.flow.rotation.event.ExecuteRotationTriggerEvent; -import com.sequenceiq.flow.rotation.event.FinalizeRotationTriggerEvent; -import com.sequenceiq.flow.rotation.event.PreValidateRotationFinishedEvent; -import com.sequenceiq.flow.rotation.event.PreValidateRotationTriggerEvent; -import com.sequenceiq.flow.rotation.event.RollbackRotationTriggerEvent; -import com.sequenceiq.flow.rotation.event.RotationEvent; -import com.sequenceiq.flow.rotation.event.RotationFailedEvent; -import com.sequenceiq.flow.rotation.event.SecretRotationTriggerEvent; -import com.sequenceiq.flow.rotation.status.service.SecretRotationStatusService; @Configuration public class SecretRotationActions { @@ -47,10 +47,10 @@ public class SecretRotationActions { private SecretRotationStatusService secretRotationStatusService; @Inject - private Optional secretRotationUsageProcessor; + private SecretRotationUsageService secretRotationUsageService; @Inject - private SecretRotationProgressService secretRotationProgressService; + private SecretRotationStepProgressService secretRotationProgressService; @Bean(name = "PRE_VALIDATE_ROTATION_STATE") public Action executePreValidationAction() { @@ -182,8 +182,7 @@ protected void doExecute(RotationFlowContext context, RotationFailedEvent payloa flow.setFlowFailed(payload.getException()); } secretRotationProgressService.deleteAll(context.getResourceCrn(), payload.getSecretType()); - secretRotationUsageProcessor.ifPresent(processor -> processor.rotationFailed(context.getSecretType(), resourceCrn, - message, context.getExecutionType())); + secretRotationUsageService.rotationFailed(context.getSecretType(), resourceCrn, message, context.getExecutionType()); LOGGER.debug("Secret rotation failed, change resource status for {}", resourceCrn); secretRotationStatusService.rotationFailed(resourceCrn, message); LOGGER.debug("Secret rotation failed, resource status changed for {}", resourceCrn); diff --git a/flow/src/main/java/com/sequenceiq/flow/rotation/config/SecretRotationEvent.java b/secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/flow/rotation/config/SecretRotationEvent.java similarity index 65% rename from flow/src/main/java/com/sequenceiq/flow/rotation/config/SecretRotationEvent.java rename to secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/flow/rotation/config/SecretRotationEvent.java index 37f8d9e357e..49d75c96fdd 100644 --- a/flow/src/main/java/com/sequenceiq/flow/rotation/config/SecretRotationEvent.java +++ b/secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/flow/rotation/config/SecretRotationEvent.java @@ -1,12 +1,12 @@ -package com.sequenceiq.flow.rotation.config; +package com.sequenceiq.cloudbreak.rotation.flow.rotation.config; +import com.sequenceiq.cloudbreak.rotation.flow.rotation.event.ExecuteRotationFailedEvent; +import com.sequenceiq.cloudbreak.rotation.flow.rotation.event.ExecuteRotationFinishedEvent; +import com.sequenceiq.cloudbreak.rotation.flow.rotation.event.PreValidateRotationFinishedEvent; +import com.sequenceiq.cloudbreak.rotation.flow.rotation.event.RotationFailedEvent; +import com.sequenceiq.cloudbreak.rotation.flow.rotation.event.SecretRotationTriggerEvent; import com.sequenceiq.flow.core.FlowEvent; import com.sequenceiq.flow.event.EventSelectorUtil; -import com.sequenceiq.flow.rotation.event.ExecuteRotationFailedEvent; -import com.sequenceiq.flow.rotation.event.ExecuteRotationFinishedEvent; -import com.sequenceiq.flow.rotation.event.PreValidateRotationFinishedEvent; -import com.sequenceiq.flow.rotation.event.RotationFailedEvent; -import com.sequenceiq.flow.rotation.event.SecretRotationTriggerEvent; public enum SecretRotationEvent implements FlowEvent { diff --git a/flow/src/main/java/com/sequenceiq/flow/rotation/config/SecretRotationFlowConfig.java b/secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/flow/rotation/config/SecretRotationFlowConfig.java similarity index 98% rename from flow/src/main/java/com/sequenceiq/flow/rotation/config/SecretRotationFlowConfig.java rename to secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/flow/rotation/config/SecretRotationFlowConfig.java index 5924f655474..e959654e794 100644 --- a/flow/src/main/java/com/sequenceiq/flow/rotation/config/SecretRotationFlowConfig.java +++ b/secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/flow/rotation/config/SecretRotationFlowConfig.java @@ -1,4 +1,4 @@ -package com.sequenceiq.flow.rotation.config; +package com.sequenceiq.cloudbreak.rotation.flow.rotation.config; import java.util.List; diff --git a/flow/src/main/java/com/sequenceiq/flow/rotation/config/SecretRotationState.java b/secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/flow/rotation/config/SecretRotationState.java similarity index 88% rename from flow/src/main/java/com/sequenceiq/flow/rotation/config/SecretRotationState.java rename to secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/flow/rotation/config/SecretRotationState.java index dc0ae7c067e..cf3efa6af75 100644 --- a/flow/src/main/java/com/sequenceiq/flow/rotation/config/SecretRotationState.java +++ b/secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/flow/rotation/config/SecretRotationState.java @@ -1,4 +1,4 @@ -package com.sequenceiq.flow.rotation.config; +package com.sequenceiq.cloudbreak.rotation.flow.rotation.config; import com.sequenceiq.flow.core.FlowState; import com.sequenceiq.flow.core.RestartAction; diff --git a/flow/src/main/java/com/sequenceiq/flow/rotation/event/ExecuteRotationFailedEvent.java b/secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/flow/rotation/event/ExecuteRotationFailedEvent.java similarity index 82% rename from flow/src/main/java/com/sequenceiq/flow/rotation/event/ExecuteRotationFailedEvent.java rename to secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/flow/rotation/event/ExecuteRotationFailedEvent.java index 23595bdfc56..f4bc9fdbfc6 100644 --- a/flow/src/main/java/com/sequenceiq/flow/rotation/event/ExecuteRotationFailedEvent.java +++ b/secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/flow/rotation/event/ExecuteRotationFailedEvent.java @@ -1,10 +1,10 @@ -package com.sequenceiq.flow.rotation.event; +package com.sequenceiq.cloudbreak.rotation.flow.rotation.event; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; -import com.sequenceiq.cloudbreak.rotation.secret.RotationFlowExecutionType; -import com.sequenceiq.cloudbreak.rotation.secret.SecretType; -import com.sequenceiq.cloudbreak.rotation.secret.step.SecretRotationStep; +import com.sequenceiq.cloudbreak.rotation.RotationFlowExecutionType; +import com.sequenceiq.cloudbreak.rotation.SecretRotationStep; +import com.sequenceiq.cloudbreak.rotation.SecretType; import com.sequenceiq.flow.event.EventSelectorUtil; public class ExecuteRotationFailedEvent extends RotationFailedEvent { diff --git a/flow/src/main/java/com/sequenceiq/flow/rotation/event/ExecuteRotationFinishedEvent.java b/secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/flow/rotation/event/ExecuteRotationFinishedEvent.java similarity index 84% rename from flow/src/main/java/com/sequenceiq/flow/rotation/event/ExecuteRotationFinishedEvent.java rename to secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/flow/rotation/event/ExecuteRotationFinishedEvent.java index 9ee65005c53..87e213dbe72 100644 --- a/flow/src/main/java/com/sequenceiq/flow/rotation/event/ExecuteRotationFinishedEvent.java +++ b/secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/flow/rotation/event/ExecuteRotationFinishedEvent.java @@ -1,9 +1,9 @@ -package com.sequenceiq.flow.rotation.event; +package com.sequenceiq.cloudbreak.rotation.flow.rotation.event; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; -import com.sequenceiq.cloudbreak.rotation.secret.RotationFlowExecutionType; -import com.sequenceiq.cloudbreak.rotation.secret.SecretType; +import com.sequenceiq.cloudbreak.rotation.RotationFlowExecutionType; +import com.sequenceiq.cloudbreak.rotation.SecretType; import com.sequenceiq.flow.event.EventSelectorUtil; public class ExecuteRotationFinishedEvent extends RotationEvent { diff --git a/flow/src/main/java/com/sequenceiq/flow/rotation/event/ExecuteRotationTriggerEvent.java b/secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/flow/rotation/event/ExecuteRotationTriggerEvent.java similarity index 84% rename from flow/src/main/java/com/sequenceiq/flow/rotation/event/ExecuteRotationTriggerEvent.java rename to secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/flow/rotation/event/ExecuteRotationTriggerEvent.java index 955b2e33edc..36bde4895d4 100644 --- a/flow/src/main/java/com/sequenceiq/flow/rotation/event/ExecuteRotationTriggerEvent.java +++ b/secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/flow/rotation/event/ExecuteRotationTriggerEvent.java @@ -1,9 +1,9 @@ -package com.sequenceiq.flow.rotation.event; +package com.sequenceiq.cloudbreak.rotation.flow.rotation.event; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; -import com.sequenceiq.cloudbreak.rotation.secret.RotationFlowExecutionType; -import com.sequenceiq.cloudbreak.rotation.secret.SecretType; +import com.sequenceiq.cloudbreak.rotation.RotationFlowExecutionType; +import com.sequenceiq.cloudbreak.rotation.SecretType; import com.sequenceiq.flow.event.EventSelectorUtil; public class ExecuteRotationTriggerEvent extends RotationEvent { diff --git a/flow/src/main/java/com/sequenceiq/flow/rotation/event/FinalizeRotationSuccessEvent.java b/secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/flow/rotation/event/FinalizeRotationSuccessEvent.java similarity index 83% rename from flow/src/main/java/com/sequenceiq/flow/rotation/event/FinalizeRotationSuccessEvent.java rename to secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/flow/rotation/event/FinalizeRotationSuccessEvent.java index 1773d6b55dd..8bf43dc8fe4 100644 --- a/flow/src/main/java/com/sequenceiq/flow/rotation/event/FinalizeRotationSuccessEvent.java +++ b/secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/flow/rotation/event/FinalizeRotationSuccessEvent.java @@ -1,9 +1,9 @@ -package com.sequenceiq.flow.rotation.event; +package com.sequenceiq.cloudbreak.rotation.flow.rotation.event; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; -import com.sequenceiq.cloudbreak.rotation.secret.RotationFlowExecutionType; -import com.sequenceiq.cloudbreak.rotation.secret.SecretType; +import com.sequenceiq.cloudbreak.rotation.RotationFlowExecutionType; +import com.sequenceiq.cloudbreak.rotation.SecretType; public class FinalizeRotationSuccessEvent extends RotationEvent { diff --git a/flow/src/main/java/com/sequenceiq/flow/rotation/event/FinalizeRotationTriggerEvent.java b/secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/flow/rotation/event/FinalizeRotationTriggerEvent.java similarity index 84% rename from flow/src/main/java/com/sequenceiq/flow/rotation/event/FinalizeRotationTriggerEvent.java rename to secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/flow/rotation/event/FinalizeRotationTriggerEvent.java index 30573a8f52d..eb8db6c496c 100644 --- a/flow/src/main/java/com/sequenceiq/flow/rotation/event/FinalizeRotationTriggerEvent.java +++ b/secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/flow/rotation/event/FinalizeRotationTriggerEvent.java @@ -1,9 +1,9 @@ -package com.sequenceiq.flow.rotation.event; +package com.sequenceiq.cloudbreak.rotation.flow.rotation.event; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; -import com.sequenceiq.cloudbreak.rotation.secret.RotationFlowExecutionType; -import com.sequenceiq.cloudbreak.rotation.secret.SecretType; +import com.sequenceiq.cloudbreak.rotation.RotationFlowExecutionType; +import com.sequenceiq.cloudbreak.rotation.SecretType; import com.sequenceiq.flow.event.EventSelectorUtil; public class FinalizeRotationTriggerEvent extends RotationEvent { diff --git a/flow/src/main/java/com/sequenceiq/flow/rotation/event/PreValidateRotationFinishedEvent.java b/secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/flow/rotation/event/PreValidateRotationFinishedEvent.java similarity index 84% rename from flow/src/main/java/com/sequenceiq/flow/rotation/event/PreValidateRotationFinishedEvent.java rename to secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/flow/rotation/event/PreValidateRotationFinishedEvent.java index f432dd83d6e..f52834ec58d 100644 --- a/flow/src/main/java/com/sequenceiq/flow/rotation/event/PreValidateRotationFinishedEvent.java +++ b/secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/flow/rotation/event/PreValidateRotationFinishedEvent.java @@ -1,9 +1,9 @@ -package com.sequenceiq.flow.rotation.event; +package com.sequenceiq.cloudbreak.rotation.flow.rotation.event; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; -import com.sequenceiq.cloudbreak.rotation.secret.RotationFlowExecutionType; -import com.sequenceiq.cloudbreak.rotation.secret.SecretType; +import com.sequenceiq.cloudbreak.rotation.RotationFlowExecutionType; +import com.sequenceiq.cloudbreak.rotation.SecretType; import com.sequenceiq.flow.event.EventSelectorUtil; public class PreValidateRotationFinishedEvent extends RotationEvent { diff --git a/flow/src/main/java/com/sequenceiq/flow/rotation/event/PreValidateRotationTriggerEvent.java b/secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/flow/rotation/event/PreValidateRotationTriggerEvent.java similarity index 84% rename from flow/src/main/java/com/sequenceiq/flow/rotation/event/PreValidateRotationTriggerEvent.java rename to secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/flow/rotation/event/PreValidateRotationTriggerEvent.java index 1c0765fb90d..d4d5674f3da 100644 --- a/flow/src/main/java/com/sequenceiq/flow/rotation/event/PreValidateRotationTriggerEvent.java +++ b/secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/flow/rotation/event/PreValidateRotationTriggerEvent.java @@ -1,9 +1,9 @@ -package com.sequenceiq.flow.rotation.event; +package com.sequenceiq.cloudbreak.rotation.flow.rotation.event; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; -import com.sequenceiq.cloudbreak.rotation.secret.RotationFlowExecutionType; -import com.sequenceiq.cloudbreak.rotation.secret.SecretType; +import com.sequenceiq.cloudbreak.rotation.RotationFlowExecutionType; +import com.sequenceiq.cloudbreak.rotation.SecretType; import com.sequenceiq.flow.event.EventSelectorUtil; public class PreValidateRotationTriggerEvent extends RotationEvent { diff --git a/flow/src/main/java/com/sequenceiq/flow/rotation/event/RollbackRotationTriggerEvent.java b/secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/flow/rotation/event/RollbackRotationTriggerEvent.java similarity index 82% rename from flow/src/main/java/com/sequenceiq/flow/rotation/event/RollbackRotationTriggerEvent.java rename to secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/flow/rotation/event/RollbackRotationTriggerEvent.java index 2d974a0b5b0..475545ebb2c 100644 --- a/flow/src/main/java/com/sequenceiq/flow/rotation/event/RollbackRotationTriggerEvent.java +++ b/secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/flow/rotation/event/RollbackRotationTriggerEvent.java @@ -1,10 +1,10 @@ -package com.sequenceiq.flow.rotation.event; +package com.sequenceiq.cloudbreak.rotation.flow.rotation.event; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; -import com.sequenceiq.cloudbreak.rotation.secret.RotationFlowExecutionType; -import com.sequenceiq.cloudbreak.rotation.secret.SecretType; -import com.sequenceiq.cloudbreak.rotation.secret.step.SecretRotationStep; +import com.sequenceiq.cloudbreak.rotation.RotationFlowExecutionType; +import com.sequenceiq.cloudbreak.rotation.SecretRotationStep; +import com.sequenceiq.cloudbreak.rotation.SecretType; import com.sequenceiq.flow.event.EventSelectorUtil; public class RollbackRotationTriggerEvent extends RotationFailedEvent { diff --git a/flow/src/main/java/com/sequenceiq/flow/rotation/event/RotationEvent.java b/secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/flow/rotation/event/RotationEvent.java similarity index 85% rename from flow/src/main/java/com/sequenceiq/flow/rotation/event/RotationEvent.java rename to secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/flow/rotation/event/RotationEvent.java index 69584d9269d..d68a53dba23 100644 --- a/flow/src/main/java/com/sequenceiq/flow/rotation/event/RotationEvent.java +++ b/secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/flow/rotation/event/RotationEvent.java @@ -1,4 +1,4 @@ -package com.sequenceiq.flow.rotation.event; +package com.sequenceiq.cloudbreak.rotation.flow.rotation.event; import java.util.Objects; @@ -9,12 +9,12 @@ import com.sequenceiq.cloudbreak.common.event.AcceptResult; import com.sequenceiq.cloudbreak.common.json.JsonIgnoreDeserialization; import com.sequenceiq.cloudbreak.eventbus.Promise; -import com.sequenceiq.cloudbreak.rotation.secret.RotationFlowExecutionType; -import com.sequenceiq.cloudbreak.rotation.secret.SecretType; +import com.sequenceiq.cloudbreak.rotation.RotationFlowExecutionType; +import com.sequenceiq.cloudbreak.rotation.SecretType; +import com.sequenceiq.cloudbreak.rotation.flow.rotation.RotationFlowContext; +import com.sequenceiq.cloudbreak.rotation.flow.serialization.SecretTypeDeserializer; +import com.sequenceiq.cloudbreak.rotation.flow.serialization.SecretTypeSerializer; import com.sequenceiq.flow.reactor.api.event.BaseFlowEvent; -import com.sequenceiq.flow.rotation.RotationFlowContext; -import com.sequenceiq.flow.rotation.serialization.SecretTypeDeserializer; -import com.sequenceiq.flow.rotation.serialization.SecretTypeSerializer; public class RotationEvent extends BaseFlowEvent { diff --git a/flow/src/main/java/com/sequenceiq/flow/rotation/event/RotationFailedEvent.java b/secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/flow/rotation/event/RotationFailedEvent.java similarity index 78% rename from flow/src/main/java/com/sequenceiq/flow/rotation/event/RotationFailedEvent.java rename to secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/flow/rotation/event/RotationFailedEvent.java index 6bcfcdf1096..3cf86241e5b 100644 --- a/flow/src/main/java/com/sequenceiq/flow/rotation/event/RotationFailedEvent.java +++ b/secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/flow/rotation/event/RotationFailedEvent.java @@ -1,14 +1,14 @@ -package com.sequenceiq.flow.rotation.event; +package com.sequenceiq.cloudbreak.rotation.flow.rotation.event; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.fasterxml.jackson.databind.annotation.JsonSerialize; -import com.sequenceiq.cloudbreak.rotation.secret.RotationFlowExecutionType; -import com.sequenceiq.cloudbreak.rotation.secret.SecretType; -import com.sequenceiq.cloudbreak.rotation.secret.serialization.SecretRotationStepDeserializer; -import com.sequenceiq.cloudbreak.rotation.secret.serialization.SecretRotationStepSerializer; -import com.sequenceiq.cloudbreak.rotation.secret.step.SecretRotationStep; +import com.sequenceiq.cloudbreak.rotation.RotationFlowExecutionType; +import com.sequenceiq.cloudbreak.rotation.SecretRotationStep; +import com.sequenceiq.cloudbreak.rotation.SecretType; +import com.sequenceiq.cloudbreak.rotation.serialization.SecretRotationStepDeserializer; +import com.sequenceiq.cloudbreak.rotation.serialization.SecretRotationStepSerializer; public class RotationFailedEvent extends RotationEvent { diff --git a/flow/src/main/java/com/sequenceiq/flow/rotation/event/SecretRotationTriggerEvent.java b/secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/flow/rotation/event/SecretRotationTriggerEvent.java similarity index 83% rename from flow/src/main/java/com/sequenceiq/flow/rotation/event/SecretRotationTriggerEvent.java rename to secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/flow/rotation/event/SecretRotationTriggerEvent.java index 55196c03ad9..7c53840f5be 100644 --- a/flow/src/main/java/com/sequenceiq/flow/rotation/event/SecretRotationTriggerEvent.java +++ b/secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/flow/rotation/event/SecretRotationTriggerEvent.java @@ -1,14 +1,14 @@ -package com.sequenceiq.flow.rotation.event; +package com.sequenceiq.cloudbreak.rotation.flow.rotation.event; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; import com.sequenceiq.cloudbreak.common.event.AcceptResult; import com.sequenceiq.cloudbreak.common.json.JsonIgnoreDeserialization; import com.sequenceiq.cloudbreak.eventbus.Promise; -import com.sequenceiq.cloudbreak.rotation.secret.RotationFlowExecutionType; -import com.sequenceiq.cloudbreak.rotation.secret.SecretType; +import com.sequenceiq.cloudbreak.rotation.RotationFlowExecutionType; +import com.sequenceiq.cloudbreak.rotation.SecretType; +import com.sequenceiq.cloudbreak.rotation.flow.chain.SecretRotationFlowChainTriggerEvent; import com.sequenceiq.flow.event.EventSelectorUtil; -import com.sequenceiq.flow.rotation.chain.SecretRotationFlowChainTriggerEvent; public class SecretRotationTriggerEvent extends RotationEvent { diff --git a/flow/src/main/java/com/sequenceiq/flow/rotation/handler/ExecuteRotationHandler.java b/secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/flow/rotation/handler/ExecuteRotationHandler.java similarity index 63% rename from flow/src/main/java/com/sequenceiq/flow/rotation/handler/ExecuteRotationHandler.java rename to secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/flow/rotation/handler/ExecuteRotationHandler.java index a80ecc68c8c..d98f297f778 100644 --- a/flow/src/main/java/com/sequenceiq/flow/rotation/handler/ExecuteRotationHandler.java +++ b/secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/flow/rotation/handler/ExecuteRotationHandler.java @@ -1,6 +1,4 @@ -package com.sequenceiq.flow.rotation.handler; - -import java.util.Optional; +package com.sequenceiq.cloudbreak.rotation.flow.rotation.handler; import javax.inject.Inject; @@ -8,15 +6,15 @@ import com.sequenceiq.cloudbreak.common.event.Selectable; import com.sequenceiq.cloudbreak.eventbus.Event; -import com.sequenceiq.cloudbreak.rotation.secret.SecretRotationException; -import com.sequenceiq.cloudbreak.rotation.secret.usage.SecretRotationUsageProcessor; +import com.sequenceiq.cloudbreak.rotation.common.SecretRotationException; +import com.sequenceiq.cloudbreak.rotation.flow.rotation.event.ExecuteRotationFailedEvent; +import com.sequenceiq.cloudbreak.rotation.flow.rotation.event.ExecuteRotationFinishedEvent; +import com.sequenceiq.cloudbreak.rotation.flow.rotation.event.ExecuteRotationTriggerEvent; +import com.sequenceiq.cloudbreak.rotation.service.SecretRotationService; +import com.sequenceiq.cloudbreak.rotation.service.usage.SecretRotationUsageService; import com.sequenceiq.flow.event.EventSelectorUtil; import com.sequenceiq.flow.reactor.api.handler.ExceptionCatcherEventHandler; import com.sequenceiq.flow.reactor.api.handler.HandlerEvent; -import com.sequenceiq.flow.rotation.event.ExecuteRotationFailedEvent; -import com.sequenceiq.flow.rotation.event.ExecuteRotationFinishedEvent; -import com.sequenceiq.flow.rotation.event.ExecuteRotationTriggerEvent; -import com.sequenceiq.flow.rotation.service.SecretRotationService; @Component public class ExecuteRotationHandler extends ExceptionCatcherEventHandler { @@ -25,7 +23,7 @@ public class ExecuteRotationHandler extends ExceptionCatcherEventHandler secretRotationUsageProcessor; + private SecretRotationUsageService secretRotationUsageService; @Override public String selector() { @@ -40,8 +38,7 @@ protected Selectable defaultFailureEvent(Long resourceId, Exception e, Event event) { ExecuteRotationTriggerEvent rotationEvent = event.getData(); - secretRotationUsageProcessor.ifPresent(processor -> processor.rotationStarted(rotationEvent.getSecretType(), - rotationEvent.getResourceCrn(), rotationEvent.getExecutionType())); + secretRotationUsageService.rotationStarted(rotationEvent.getSecretType(), rotationEvent.getResourceCrn(), rotationEvent.getExecutionType()); secretRotationService.executeRotation(rotationEvent.getSecretType(), rotationEvent.getResourceCrn(), rotationEvent.getExecutionType()); return ExecuteRotationFinishedEvent.fromPayload(rotationEvent); } diff --git a/flow/src/main/java/com/sequenceiq/flow/rotation/handler/FinalizeRotationHandler.java b/secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/flow/rotation/handler/FinalizeRotationHandler.java similarity index 63% rename from flow/src/main/java/com/sequenceiq/flow/rotation/handler/FinalizeRotationHandler.java rename to secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/flow/rotation/handler/FinalizeRotationHandler.java index 93377b7c12b..185159c3c25 100644 --- a/flow/src/main/java/com/sequenceiq/flow/rotation/handler/FinalizeRotationHandler.java +++ b/secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/flow/rotation/handler/FinalizeRotationHandler.java @@ -1,6 +1,4 @@ -package com.sequenceiq.flow.rotation.handler; - -import java.util.Optional; +package com.sequenceiq.cloudbreak.rotation.flow.rotation.handler; import javax.inject.Inject; @@ -8,16 +6,16 @@ import com.sequenceiq.cloudbreak.common.event.Selectable; import com.sequenceiq.cloudbreak.eventbus.Event; -import com.sequenceiq.cloudbreak.rotation.secret.SecretRotationException; -import com.sequenceiq.cloudbreak.rotation.secret.usage.SecretRotationUsageProcessor; +import com.sequenceiq.cloudbreak.rotation.common.SecretRotationException; +import com.sequenceiq.cloudbreak.rotation.flow.rotation.config.SecretRotationEvent; +import com.sequenceiq.cloudbreak.rotation.flow.rotation.event.FinalizeRotationSuccessEvent; +import com.sequenceiq.cloudbreak.rotation.flow.rotation.event.FinalizeRotationTriggerEvent; +import com.sequenceiq.cloudbreak.rotation.flow.rotation.event.RotationFailedEvent; +import com.sequenceiq.cloudbreak.rotation.service.SecretRotationService; +import com.sequenceiq.cloudbreak.rotation.service.usage.SecretRotationUsageService; import com.sequenceiq.flow.event.EventSelectorUtil; import com.sequenceiq.flow.reactor.api.handler.ExceptionCatcherEventHandler; import com.sequenceiq.flow.reactor.api.handler.HandlerEvent; -import com.sequenceiq.flow.rotation.config.SecretRotationEvent; -import com.sequenceiq.flow.rotation.event.FinalizeRotationSuccessEvent; -import com.sequenceiq.flow.rotation.event.FinalizeRotationTriggerEvent; -import com.sequenceiq.flow.rotation.event.RotationFailedEvent; -import com.sequenceiq.flow.rotation.service.SecretRotationService; @Component public class FinalizeRotationHandler extends ExceptionCatcherEventHandler { @@ -26,7 +24,7 @@ public class FinalizeRotationHandler extends ExceptionCatcherEventHandler secretRotationUsageProcessor; + private SecretRotationUsageService secretRotationUsageService; @Override public String selector() { @@ -43,8 +41,7 @@ protected Selectable defaultFailureEvent(Long resourceId, Exception e, Event event) { FinalizeRotationTriggerEvent finalizeEvent = event.getData(); secretRotationService.finalizeRotation(finalizeEvent.getSecretType(), finalizeEvent.getResourceCrn(), finalizeEvent.getExecutionType()); - secretRotationUsageProcessor.ifPresent(processor -> processor.rotationFinished(finalizeEvent.getSecretType(), finalizeEvent.getResourceCrn(), - finalizeEvent.getExecutionType())); + secretRotationUsageService.rotationFinished(finalizeEvent.getSecretType(), finalizeEvent.getResourceCrn(), finalizeEvent.getExecutionType()); return FinalizeRotationSuccessEvent.fromPayload(SecretRotationEvent.ROTATION_FINISHED_EVENT.event(), finalizeEvent); } } diff --git a/flow/src/main/java/com/sequenceiq/flow/rotation/handler/PreValidateRotationHandler.java b/secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/flow/rotation/handler/PreValidateRotationHandler.java similarity index 71% rename from flow/src/main/java/com/sequenceiq/flow/rotation/handler/PreValidateRotationHandler.java rename to secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/flow/rotation/handler/PreValidateRotationHandler.java index 17c767e3ffa..34faf7e2664 100644 --- a/flow/src/main/java/com/sequenceiq/flow/rotation/handler/PreValidateRotationHandler.java +++ b/secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/flow/rotation/handler/PreValidateRotationHandler.java @@ -1,4 +1,4 @@ -package com.sequenceiq.flow.rotation.handler; +package com.sequenceiq.cloudbreak.rotation.flow.rotation.handler; import javax.inject.Inject; @@ -6,15 +6,15 @@ import com.sequenceiq.cloudbreak.common.event.Selectable; import com.sequenceiq.cloudbreak.eventbus.Event; -import com.sequenceiq.cloudbreak.rotation.secret.SecretRotationException; +import com.sequenceiq.cloudbreak.rotation.common.SecretRotationException; +import com.sequenceiq.cloudbreak.rotation.flow.rotation.config.SecretRotationEvent; +import com.sequenceiq.cloudbreak.rotation.flow.rotation.event.PreValidateRotationFinishedEvent; +import com.sequenceiq.cloudbreak.rotation.flow.rotation.event.PreValidateRotationTriggerEvent; +import com.sequenceiq.cloudbreak.rotation.flow.rotation.event.RotationFailedEvent; +import com.sequenceiq.cloudbreak.rotation.service.SecretRotationService; import com.sequenceiq.flow.event.EventSelectorUtil; import com.sequenceiq.flow.reactor.api.handler.ExceptionCatcherEventHandler; import com.sequenceiq.flow.reactor.api.handler.HandlerEvent; -import com.sequenceiq.flow.rotation.config.SecretRotationEvent; -import com.sequenceiq.flow.rotation.event.PreValidateRotationFinishedEvent; -import com.sequenceiq.flow.rotation.event.PreValidateRotationTriggerEvent; -import com.sequenceiq.flow.rotation.event.RotationFailedEvent; -import com.sequenceiq.flow.rotation.service.SecretRotationService; @Component public class PreValidateRotationHandler extends ExceptionCatcherEventHandler { diff --git a/flow/src/main/java/com/sequenceiq/flow/rotation/handler/RollbackRotationHandler.java b/secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/flow/rotation/handler/RollbackRotationHandler.java similarity index 62% rename from flow/src/main/java/com/sequenceiq/flow/rotation/handler/RollbackRotationHandler.java rename to secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/flow/rotation/handler/RollbackRotationHandler.java index 2da52b177b3..d80a023faf8 100644 --- a/flow/src/main/java/com/sequenceiq/flow/rotation/handler/RollbackRotationHandler.java +++ b/secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/flow/rotation/handler/RollbackRotationHandler.java @@ -1,6 +1,4 @@ -package com.sequenceiq.flow.rotation.handler; - -import java.util.Optional; +package com.sequenceiq.cloudbreak.rotation.flow.rotation.handler; import javax.inject.Inject; @@ -8,17 +6,17 @@ import com.sequenceiq.cloudbreak.common.event.Selectable; import com.sequenceiq.cloudbreak.eventbus.Event; -import com.sequenceiq.cloudbreak.rotation.secret.RotationFlowExecutionType; -import com.sequenceiq.cloudbreak.rotation.secret.SecretType; -import com.sequenceiq.cloudbreak.rotation.secret.step.SecretRotationStep; -import com.sequenceiq.cloudbreak.rotation.secret.usage.SecretRotationUsageProcessor; +import com.sequenceiq.cloudbreak.rotation.RotationFlowExecutionType; +import com.sequenceiq.cloudbreak.rotation.SecretRotationStep; +import com.sequenceiq.cloudbreak.rotation.SecretType; +import com.sequenceiq.cloudbreak.rotation.flow.rotation.config.SecretRotationEvent; +import com.sequenceiq.cloudbreak.rotation.flow.rotation.event.RollbackRotationTriggerEvent; +import com.sequenceiq.cloudbreak.rotation.flow.rotation.event.RotationFailedEvent; +import com.sequenceiq.cloudbreak.rotation.service.SecretRotationService; +import com.sequenceiq.cloudbreak.rotation.service.usage.SecretRotationUsageService; import com.sequenceiq.flow.event.EventSelectorUtil; import com.sequenceiq.flow.reactor.api.handler.ExceptionCatcherEventHandler; import com.sequenceiq.flow.reactor.api.handler.HandlerEvent; -import com.sequenceiq.flow.rotation.config.SecretRotationEvent; -import com.sequenceiq.flow.rotation.event.RollbackRotationTriggerEvent; -import com.sequenceiq.flow.rotation.event.RotationFailedEvent; -import com.sequenceiq.flow.rotation.service.SecretRotationService; @Component public class RollbackRotationHandler extends ExceptionCatcherEventHandler { @@ -27,7 +25,7 @@ public class RollbackRotationHandler extends ExceptionCatcherEventHandler secretRotationUsageProcessor; + private SecretRotationUsageService secretRotationUsageService; @Override public String selector() { @@ -47,13 +45,13 @@ protected Selectable doAccept(HandlerEvent event) SecretType secretType = rollbackEvent.getSecretType(); Exception exception = rollbackEvent.getException(); SecretRotationStep failedStep = rollbackEvent.getFailedStep(); - secretRotationUsageProcessor.ifPresent(processor -> processor.rollbackStarted(secretType, resourceCrn, executionType)); + secretRotationUsageService.rollbackStarted(secretType, resourceCrn, executionType); try { secretRotationService.rollbackRotation(secretType, resourceCrn, executionType, failedStep); - secretRotationUsageProcessor.ifPresent(processor -> processor.rollbackFinished(secretType, resourceCrn, executionType)); + secretRotationUsageService.rollbackFinished(secretType, resourceCrn, executionType); return RotationFailedEvent.fromPayload(SecretRotationEvent.ROTATION_FAILED_EVENT.event(), rollbackEvent, exception, failedStep); } catch (Exception e) { - secretRotationUsageProcessor.ifPresent(processor -> processor.rollbackFailed(secretType, resourceCrn, e.getMessage(), executionType)); + secretRotationUsageService.rollbackFailed(secretType, resourceCrn, e.getMessage(), executionType); throw e; } } diff --git a/flow/src/main/java/com/sequenceiq/flow/rotation/serialization/SecretTypeDeserializer.java b/secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/flow/serialization/SecretTypeDeserializer.java similarity index 70% rename from flow/src/main/java/com/sequenceiq/flow/rotation/serialization/SecretTypeDeserializer.java rename to secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/flow/serialization/SecretTypeDeserializer.java index 7fbcdd47e16..33b804abc12 100644 --- a/flow/src/main/java/com/sequenceiq/flow/rotation/serialization/SecretTypeDeserializer.java +++ b/secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/flow/serialization/SecretTypeDeserializer.java @@ -1,12 +1,12 @@ -package com.sequenceiq.flow.rotation.serialization; +package com.sequenceiq.cloudbreak.rotation.flow.serialization; import java.io.IOException; import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.databind.DeserializationContext; import com.fasterxml.jackson.databind.JsonDeserializer; -import com.sequenceiq.cloudbreak.rotation.secret.SecretType; -import com.sequenceiq.cloudbreak.rotation.secret.serialization.SecretRotationEnumSerializationUtil; +import com.sequenceiq.cloudbreak.rotation.SecretType; +import com.sequenceiq.cloudbreak.rotation.serialization.SecretRotationEnumSerializationUtil; public class SecretTypeDeserializer extends JsonDeserializer> { diff --git a/flow/src/main/java/com/sequenceiq/flow/rotation/serialization/SecretTypeListDeserializer.java b/secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/flow/serialization/SecretTypeListDeserializer.java similarity index 68% rename from flow/src/main/java/com/sequenceiq/flow/rotation/serialization/SecretTypeListDeserializer.java rename to secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/flow/serialization/SecretTypeListDeserializer.java index 8fb02fd1f37..6720d037a72 100644 --- a/flow/src/main/java/com/sequenceiq/flow/rotation/serialization/SecretTypeListDeserializer.java +++ b/secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/flow/serialization/SecretTypeListDeserializer.java @@ -1,8 +1,8 @@ -package com.sequenceiq.flow.rotation.serialization; +package com.sequenceiq.cloudbreak.rotation.flow.serialization; -import static com.sequenceiq.cloudbreak.rotation.secret.serialization.SecretRotationEnumSerializationUtil.getEnum; -import static com.sequenceiq.cloudbreak.rotation.secret.serialization.SecretRotationEnumSerializationUtil.listStringToList; -import static com.sequenceiq.cloudbreak.rotation.secret.serialization.SecretRotationEnumSerializationUtil.mapStringToMap; +import static com.sequenceiq.cloudbreak.rotation.serialization.SecretRotationEnumSerializationUtil.getEnum; +import static com.sequenceiq.cloudbreak.rotation.serialization.SecretRotationEnumSerializationUtil.listStringToList; +import static com.sequenceiq.cloudbreak.rotation.serialization.SecretRotationEnumSerializationUtil.mapStringToMap; import java.io.IOException; import java.util.List; @@ -11,7 +11,7 @@ import com.fasterxml.jackson.databind.DeserializationContext; import com.fasterxml.jackson.databind.JsonDeserializer; import com.google.common.collect.Lists; -import com.sequenceiq.cloudbreak.rotation.secret.SecretType; +import com.sequenceiq.cloudbreak.rotation.SecretType; public class SecretTypeListDeserializer extends JsonDeserializer>> { diff --git a/flow/src/main/java/com/sequenceiq/flow/rotation/serialization/SecretTypeListSerializer.java b/secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/flow/serialization/SecretTypeListSerializer.java similarity index 71% rename from flow/src/main/java/com/sequenceiq/flow/rotation/serialization/SecretTypeListSerializer.java rename to secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/flow/serialization/SecretTypeListSerializer.java index 65ce9feef4f..52df45d06bd 100644 --- a/flow/src/main/java/com/sequenceiq/flow/rotation/serialization/SecretTypeListSerializer.java +++ b/secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/flow/serialization/SecretTypeListSerializer.java @@ -1,6 +1,6 @@ -package com.sequenceiq.flow.rotation.serialization; +package com.sequenceiq.cloudbreak.rotation.flow.serialization; -import static com.sequenceiq.cloudbreak.rotation.secret.serialization.SecretRotationEnumSerializationUtil.listToString; +import static com.sequenceiq.cloudbreak.rotation.serialization.SecretRotationEnumSerializationUtil.listToString; import java.io.IOException; import java.util.List; @@ -9,8 +9,8 @@ import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.databind.JsonSerializer; import com.fasterxml.jackson.databind.SerializerProvider; -import com.sequenceiq.cloudbreak.rotation.secret.SecretType; -import com.sequenceiq.cloudbreak.rotation.secret.serialization.SecretRotationEnumSerializationUtil; +import com.sequenceiq.cloudbreak.rotation.SecretType; +import com.sequenceiq.cloudbreak.rotation.serialization.SecretRotationEnumSerializationUtil; public class SecretTypeListSerializer extends JsonSerializer>> { diff --git a/flow/src/main/java/com/sequenceiq/flow/rotation/serialization/SecretTypeSerializer.java b/secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/flow/serialization/SecretTypeSerializer.java similarity index 70% rename from flow/src/main/java/com/sequenceiq/flow/rotation/serialization/SecretTypeSerializer.java rename to secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/flow/serialization/SecretTypeSerializer.java index 2f6edb3328b..c9f5abb8053 100644 --- a/flow/src/main/java/com/sequenceiq/flow/rotation/serialization/SecretTypeSerializer.java +++ b/secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/flow/serialization/SecretTypeSerializer.java @@ -1,12 +1,12 @@ -package com.sequenceiq.flow.rotation.serialization; +package com.sequenceiq.cloudbreak.rotation.flow.serialization; import java.io.IOException; import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.databind.JsonSerializer; import com.fasterxml.jackson.databind.SerializerProvider; -import com.sequenceiq.cloudbreak.rotation.secret.SecretType; -import com.sequenceiq.cloudbreak.rotation.secret.serialization.SecretRotationEnumSerializationUtil; +import com.sequenceiq.cloudbreak.rotation.SecretType; +import com.sequenceiq.cloudbreak.rotation.serialization.SecretRotationEnumSerializationUtil; public class SecretTypeSerializer extends JsonSerializer> { diff --git a/flow/src/main/java/com/sequenceiq/flow/rotation/status/SecretRotationStatusChangeActions.java b/secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/flow/status/SecretRotationStatusChangeActions.java similarity index 89% rename from flow/src/main/java/com/sequenceiq/flow/rotation/status/SecretRotationStatusChangeActions.java rename to secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/flow/status/SecretRotationStatusChangeActions.java index 85074854539..bec54a0008f 100644 --- a/flow/src/main/java/com/sequenceiq/flow/rotation/status/SecretRotationStatusChangeActions.java +++ b/secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/flow/status/SecretRotationStatusChangeActions.java @@ -1,4 +1,4 @@ -package com.sequenceiq.flow.rotation.status; +package com.sequenceiq.cloudbreak.rotation.flow.status; import java.util.Map; import java.util.Optional; @@ -12,14 +12,14 @@ import org.springframework.statemachine.StateContext; import org.springframework.statemachine.action.Action; +import com.sequenceiq.cloudbreak.rotation.flow.status.event.RotationStatusChangeFailHandledEvent; +import com.sequenceiq.cloudbreak.rotation.flow.status.event.RotationStatusChangeFailedEvent; +import com.sequenceiq.cloudbreak.rotation.flow.status.event.RotationStatusChangeFinishedEvent; +import com.sequenceiq.cloudbreak.rotation.flow.status.event.RotationStatusChangeTriggerEvent; +import com.sequenceiq.cloudbreak.rotation.service.status.SecretRotationStatusService; import com.sequenceiq.flow.core.AbstractAction; import com.sequenceiq.flow.core.Flow; import com.sequenceiq.flow.core.FlowParameters; -import com.sequenceiq.flow.rotation.status.event.RotationStatusChangeFailHandledEvent; -import com.sequenceiq.flow.rotation.status.event.RotationStatusChangeFailedEvent; -import com.sequenceiq.flow.rotation.status.event.RotationStatusChangeFinishedEvent; -import com.sequenceiq.flow.rotation.status.event.RotationStatusChangeTriggerEvent; -import com.sequenceiq.flow.rotation.status.service.SecretRotationStatusService; @Configuration public class SecretRotationStatusChangeActions { diff --git a/flow/src/main/java/com/sequenceiq/flow/rotation/status/SecretRotationStatusChangeEvent.java b/secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/flow/status/SecretRotationStatusChangeEvent.java similarity index 92% rename from flow/src/main/java/com/sequenceiq/flow/rotation/status/SecretRotationStatusChangeEvent.java rename to secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/flow/status/SecretRotationStatusChangeEvent.java index e5b9846d3f9..cd1ebc3cb4b 100644 --- a/flow/src/main/java/com/sequenceiq/flow/rotation/status/SecretRotationStatusChangeEvent.java +++ b/secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/flow/status/SecretRotationStatusChangeEvent.java @@ -1,4 +1,4 @@ -package com.sequenceiq.flow.rotation.status; +package com.sequenceiq.cloudbreak.rotation.flow.status; import com.sequenceiq.flow.core.FlowEvent; diff --git a/flow/src/main/java/com/sequenceiq/flow/rotation/status/SecretRotationStatusChangeFlowConfig.java b/secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/flow/status/SecretRotationStatusChangeFlowConfig.java similarity index 98% rename from flow/src/main/java/com/sequenceiq/flow/rotation/status/SecretRotationStatusChangeFlowConfig.java rename to secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/flow/status/SecretRotationStatusChangeFlowConfig.java index 0d90416bbd5..a902ce788ca 100644 --- a/flow/src/main/java/com/sequenceiq/flow/rotation/status/SecretRotationStatusChangeFlowConfig.java +++ b/secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/flow/status/SecretRotationStatusChangeFlowConfig.java @@ -1,4 +1,4 @@ -package com.sequenceiq.flow.rotation.status; +package com.sequenceiq.cloudbreak.rotation.flow.status; import java.util.List; diff --git a/flow/src/main/java/com/sequenceiq/flow/rotation/status/SecretRotationStatusChangeFlowContext.java b/secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/flow/status/SecretRotationStatusChangeFlowContext.java similarity index 90% rename from flow/src/main/java/com/sequenceiq/flow/rotation/status/SecretRotationStatusChangeFlowContext.java rename to secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/flow/status/SecretRotationStatusChangeFlowContext.java index ccd347e190c..95399c01f28 100644 --- a/flow/src/main/java/com/sequenceiq/flow/rotation/status/SecretRotationStatusChangeFlowContext.java +++ b/secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/flow/status/SecretRotationStatusChangeFlowContext.java @@ -1,10 +1,10 @@ -package com.sequenceiq.flow.rotation.status; +package com.sequenceiq.cloudbreak.rotation.flow.status; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; +import com.sequenceiq.cloudbreak.rotation.flow.status.event.RotationStatusChangeEvent; import com.sequenceiq.flow.core.CommonContext; import com.sequenceiq.flow.core.FlowParameters; -import com.sequenceiq.flow.rotation.status.event.RotationStatusChangeEvent; public class SecretRotationStatusChangeFlowContext extends CommonContext { diff --git a/flow/src/main/java/com/sequenceiq/flow/rotation/status/SecretRotationStatusChangeState.java b/secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/flow/status/SecretRotationStatusChangeState.java similarity index 89% rename from flow/src/main/java/com/sequenceiq/flow/rotation/status/SecretRotationStatusChangeState.java rename to secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/flow/status/SecretRotationStatusChangeState.java index fb3dfeae698..72f4c060204 100644 --- a/flow/src/main/java/com/sequenceiq/flow/rotation/status/SecretRotationStatusChangeState.java +++ b/secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/flow/status/SecretRotationStatusChangeState.java @@ -1,4 +1,4 @@ -package com.sequenceiq.flow.rotation.status; +package com.sequenceiq.cloudbreak.rotation.flow.status; import com.sequenceiq.flow.core.FlowState; import com.sequenceiq.flow.core.RestartAction; diff --git a/flow/src/main/java/com/sequenceiq/flow/rotation/status/event/RotationStatusChangeEvent.java b/secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/flow/status/event/RotationStatusChangeEvent.java similarity index 95% rename from flow/src/main/java/com/sequenceiq/flow/rotation/status/event/RotationStatusChangeEvent.java rename to secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/flow/status/event/RotationStatusChangeEvent.java index d63e45c3790..edb3814327a 100644 --- a/flow/src/main/java/com/sequenceiq/flow/rotation/status/event/RotationStatusChangeEvent.java +++ b/secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/flow/status/event/RotationStatusChangeEvent.java @@ -1,4 +1,4 @@ -package com.sequenceiq.flow.rotation.status.event; +package com.sequenceiq.cloudbreak.rotation.flow.status.event; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; diff --git a/flow/src/main/java/com/sequenceiq/flow/rotation/status/event/RotationStatusChangeFailHandledEvent.java b/secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/flow/status/event/RotationStatusChangeFailHandledEvent.java similarity index 84% rename from flow/src/main/java/com/sequenceiq/flow/rotation/status/event/RotationStatusChangeFailHandledEvent.java rename to secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/flow/status/event/RotationStatusChangeFailHandledEvent.java index 269de2edf2f..18d0ddcfdf4 100644 --- a/flow/src/main/java/com/sequenceiq/flow/rotation/status/event/RotationStatusChangeFailHandledEvent.java +++ b/secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/flow/status/event/RotationStatusChangeFailHandledEvent.java @@ -1,8 +1,8 @@ -package com.sequenceiq.flow.rotation.status.event; +package com.sequenceiq.cloudbreak.rotation.flow.status.event; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; -import com.sequenceiq.flow.rotation.status.SecretRotationStatusChangeEvent; +import com.sequenceiq.cloudbreak.rotation.flow.status.SecretRotationStatusChangeEvent; public class RotationStatusChangeFailHandledEvent extends RotationStatusChangeEvent { diff --git a/flow/src/main/java/com/sequenceiq/flow/rotation/status/event/RotationStatusChangeFailedEvent.java b/secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/flow/status/event/RotationStatusChangeFailedEvent.java similarity index 87% rename from flow/src/main/java/com/sequenceiq/flow/rotation/status/event/RotationStatusChangeFailedEvent.java rename to secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/flow/status/event/RotationStatusChangeFailedEvent.java index 2a33c263228..23b1523901d 100644 --- a/flow/src/main/java/com/sequenceiq/flow/rotation/status/event/RotationStatusChangeFailedEvent.java +++ b/secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/flow/status/event/RotationStatusChangeFailedEvent.java @@ -1,8 +1,8 @@ -package com.sequenceiq.flow.rotation.status.event; +package com.sequenceiq.cloudbreak.rotation.flow.status.event; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; -import com.sequenceiq.flow.rotation.status.SecretRotationStatusChangeEvent; +import com.sequenceiq.cloudbreak.rotation.flow.status.SecretRotationStatusChangeEvent; public class RotationStatusChangeFailedEvent extends RotationStatusChangeEvent { diff --git a/flow/src/main/java/com/sequenceiq/flow/rotation/status/event/RotationStatusChangeFinishedEvent.java b/secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/flow/status/event/RotationStatusChangeFinishedEvent.java similarity index 84% rename from flow/src/main/java/com/sequenceiq/flow/rotation/status/event/RotationStatusChangeFinishedEvent.java rename to secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/flow/status/event/RotationStatusChangeFinishedEvent.java index 94ebaffdbf8..66ac2c66ccf 100644 --- a/flow/src/main/java/com/sequenceiq/flow/rotation/status/event/RotationStatusChangeFinishedEvent.java +++ b/secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/flow/status/event/RotationStatusChangeFinishedEvent.java @@ -1,8 +1,8 @@ -package com.sequenceiq.flow.rotation.status.event; +package com.sequenceiq.cloudbreak.rotation.flow.status.event; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; -import com.sequenceiq.flow.rotation.status.SecretRotationStatusChangeEvent; +import com.sequenceiq.cloudbreak.rotation.flow.status.SecretRotationStatusChangeEvent; public class RotationStatusChangeFinishedEvent extends RotationStatusChangeEvent { diff --git a/flow/src/main/java/com/sequenceiq/flow/rotation/status/event/RotationStatusChangeTriggerEvent.java b/secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/flow/status/event/RotationStatusChangeTriggerEvent.java similarity index 83% rename from flow/src/main/java/com/sequenceiq/flow/rotation/status/event/RotationStatusChangeTriggerEvent.java rename to secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/flow/status/event/RotationStatusChangeTriggerEvent.java index 5e4d3a2f3f6..70a8aaea340 100644 --- a/flow/src/main/java/com/sequenceiq/flow/rotation/status/event/RotationStatusChangeTriggerEvent.java +++ b/secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/flow/status/event/RotationStatusChangeTriggerEvent.java @@ -1,12 +1,12 @@ -package com.sequenceiq.flow.rotation.status.event; +package com.sequenceiq.cloudbreak.rotation.flow.status.event; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; import com.sequenceiq.cloudbreak.common.event.AcceptResult; import com.sequenceiq.cloudbreak.common.json.JsonIgnoreDeserialization; import com.sequenceiq.cloudbreak.eventbus.Promise; -import com.sequenceiq.flow.rotation.chain.SecretRotationFlowChainTriggerEvent; -import com.sequenceiq.flow.rotation.status.SecretRotationStatusChangeEvent; +import com.sequenceiq.cloudbreak.rotation.flow.chain.SecretRotationFlowChainTriggerEvent; +import com.sequenceiq.cloudbreak.rotation.flow.status.SecretRotationStatusChangeEvent; public class RotationStatusChangeTriggerEvent extends RotationStatusChangeEvent { diff --git a/flow/src/main/java/com/sequenceiq/flow/rotation/repository/SecretRotationStepProgressRepository.java b/secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/repository/SecretRotationStepProgressRepository.java similarity index 58% rename from flow/src/main/java/com/sequenceiq/flow/rotation/repository/SecretRotationStepProgressRepository.java rename to secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/repository/SecretRotationStepProgressRepository.java index b90d9d79ef6..d5f677dc1ce 100644 --- a/flow/src/main/java/com/sequenceiq/flow/rotation/repository/SecretRotationStepProgressRepository.java +++ b/secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/repository/SecretRotationStepProgressRepository.java @@ -1,4 +1,4 @@ -package com.sequenceiq.flow.rotation.repository; +package com.sequenceiq.cloudbreak.rotation.repository; import java.util.Set; @@ -7,10 +7,12 @@ import org.springframework.data.repository.CrudRepository; -import com.sequenceiq.cloudbreak.rotation.secret.RotationFlowExecutionType; -import com.sequenceiq.cloudbreak.rotation.secret.SecretType; -import com.sequenceiq.flow.rotation.entity.SecretRotationStepProgress; +import com.sequenceiq.cloudbreak.rotation.RotationFlowExecutionType; +import com.sequenceiq.cloudbreak.rotation.SecretType; +import com.sequenceiq.cloudbreak.rotation.entity.SecretRotationStepProgress; +import com.sequenceiq.cloudbreak.workspace.repository.EntityType; +@EntityType(entityClass = SecretRotationStepProgress.class) @Transactional(TxType.REQUIRED) public interface SecretRotationStepProgressRepository extends CrudRepository { diff --git a/common/src/main/java/com/sequenceiq/cloudbreak/rotation/secret/CustomJobExecutor.java b/secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/secret/custom/CustomJobExecutor.java similarity index 80% rename from common/src/main/java/com/sequenceiq/cloudbreak/rotation/secret/CustomJobExecutor.java rename to secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/secret/custom/CustomJobExecutor.java index 5a6746e0fbe..a8f5d94670c 100644 --- a/common/src/main/java/com/sequenceiq/cloudbreak/rotation/secret/CustomJobExecutor.java +++ b/secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/secret/custom/CustomJobExecutor.java @@ -1,10 +1,10 @@ -package com.sequenceiq.cloudbreak.rotation.secret; +package com.sequenceiq.cloudbreak.rotation.secret.custom; import org.springframework.stereotype.Component; -import com.sequenceiq.cloudbreak.rotation.secret.context.CustomJobRotationContext; -import com.sequenceiq.cloudbreak.rotation.secret.step.CommonSecretRotationStep; -import com.sequenceiq.cloudbreak.rotation.secret.step.SecretRotationStep; +import com.sequenceiq.cloudbreak.rotation.CommonSecretRotationStep; +import com.sequenceiq.cloudbreak.rotation.SecretRotationStep; +import com.sequenceiq.cloudbreak.rotation.executor.AbstractRotationExecutor; @Component public class CustomJobExecutor extends AbstractRotationExecutor { diff --git a/common/src/main/java/com/sequenceiq/cloudbreak/rotation/secret/context/CustomJobRotationContext.java b/secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/secret/custom/CustomJobRotationContext.java similarity index 94% rename from common/src/main/java/com/sequenceiq/cloudbreak/rotation/secret/context/CustomJobRotationContext.java rename to secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/secret/custom/CustomJobRotationContext.java index c633087c5e3..be7ecc7c442 100644 --- a/common/src/main/java/com/sequenceiq/cloudbreak/rotation/secret/context/CustomJobRotationContext.java +++ b/secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/secret/custom/CustomJobRotationContext.java @@ -1,8 +1,8 @@ -package com.sequenceiq.cloudbreak.rotation.secret.context; +package com.sequenceiq.cloudbreak.rotation.secret.custom; import java.util.Optional; -import com.sequenceiq.cloudbreak.rotation.secret.RotationContext; +import com.sequenceiq.cloudbreak.rotation.common.RotationContext; public class CustomJobRotationContext extends RotationContext { diff --git a/common/src/main/java/com/sequenceiq/cloudbreak/rotation/secret/context/PollerRotationContext.java b/secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/secret/poller/PollerRotationContext.java similarity index 64% rename from common/src/main/java/com/sequenceiq/cloudbreak/rotation/secret/context/PollerRotationContext.java rename to secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/secret/poller/PollerRotationContext.java index 20438ac6bbc..d7f855467f4 100644 --- a/common/src/main/java/com/sequenceiq/cloudbreak/rotation/secret/context/PollerRotationContext.java +++ b/secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/secret/poller/PollerRotationContext.java @@ -1,7 +1,7 @@ -package com.sequenceiq.cloudbreak.rotation.secret.context; +package com.sequenceiq.cloudbreak.rotation.secret.poller; -import com.sequenceiq.cloudbreak.rotation.secret.RotationContext; -import com.sequenceiq.cloudbreak.rotation.secret.SecretType; +import com.sequenceiq.cloudbreak.rotation.SecretType; +import com.sequenceiq.cloudbreak.rotation.common.RotationContext; public class PollerRotationContext extends RotationContext { diff --git a/orchestrator-salt/src/main/java/com/sequenceiq/cloudbreak/orchestrator/salt/rotation/SaltBootPasswordUserDataModifier.java b/secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/secret/saltboot/SaltBootPasswordUserDataModifier.java similarity index 87% rename from orchestrator-salt/src/main/java/com/sequenceiq/cloudbreak/orchestrator/salt/rotation/SaltBootPasswordUserDataModifier.java rename to secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/secret/saltboot/SaltBootPasswordUserDataModifier.java index 2cef08277ee..216495d6f5f 100644 --- a/orchestrator-salt/src/main/java/com/sequenceiq/cloudbreak/orchestrator/salt/rotation/SaltBootPasswordUserDataModifier.java +++ b/secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/secret/saltboot/SaltBootPasswordUserDataModifier.java @@ -1,4 +1,4 @@ -package com.sequenceiq.cloudbreak.orchestrator.salt.rotation; +package com.sequenceiq.cloudbreak.rotation.secret.saltboot; import org.springframework.stereotype.Component; diff --git a/orchestrator-salt/src/main/java/com/sequenceiq/cloudbreak/orchestrator/salt/rotation/SaltBootSignKeyUserDataModifier.java b/secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/secret/saltboot/SaltBootSignKeyUserDataModifier.java similarity index 91% rename from orchestrator-salt/src/main/java/com/sequenceiq/cloudbreak/orchestrator/salt/rotation/SaltBootSignKeyUserDataModifier.java rename to secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/secret/saltboot/SaltBootSignKeyUserDataModifier.java index 8f8b1dcf906..27eceee7d77 100644 --- a/orchestrator-salt/src/main/java/com/sequenceiq/cloudbreak/orchestrator/salt/rotation/SaltBootSignKeyUserDataModifier.java +++ b/secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/secret/saltboot/SaltBootSignKeyUserDataModifier.java @@ -1,4 +1,4 @@ -package com.sequenceiq.cloudbreak.orchestrator.salt.rotation; +package com.sequenceiq.cloudbreak.rotation.secret.saltboot; import org.apache.commons.codec.binary.Base64; import org.springframework.stereotype.Component; diff --git a/cloud-api/src/main/java/com/sequenceiq/cloudbreak/cloud/rotation/UserDataRotationContext.java b/secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/secret/userdata/UserDataRotationContext.java similarity index 73% rename from cloud-api/src/main/java/com/sequenceiq/cloudbreak/cloud/rotation/UserDataRotationContext.java rename to secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/secret/userdata/UserDataRotationContext.java index 114a82f5b38..c5f2544acde 100644 --- a/cloud-api/src/main/java/com/sequenceiq/cloudbreak/cloud/rotation/UserDataRotationContext.java +++ b/secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/secret/userdata/UserDataRotationContext.java @@ -1,11 +1,10 @@ -package com.sequenceiq.cloudbreak.cloud.rotation; +package com.sequenceiq.cloudbreak.rotation.secret.userdata; import java.util.List; import org.apache.commons.lang3.tuple.Pair; -import com.sequenceiq.cloudbreak.rotation.secret.RotationContext; -import com.sequenceiq.cloudbreak.rotation.secret.userdata.UserDataSecretModifier; +import com.sequenceiq.cloudbreak.rotation.common.RotationContext; public class UserDataRotationContext extends RotationContext { diff --git a/common/src/main/java/com/sequenceiq/cloudbreak/rotation/secret/userdata/UserDataSecretModifier.java b/secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/secret/userdata/UserDataSecretModifier.java similarity index 100% rename from common/src/main/java/com/sequenceiq/cloudbreak/rotation/secret/userdata/UserDataSecretModifier.java rename to secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/secret/userdata/UserDataSecretModifier.java diff --git a/common/src/main/java/com/sequenceiq/cloudbreak/rotation/secret/vault/VaultRotationContext.java b/secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/secret/vault/VaultRotationContext.java similarity index 96% rename from common/src/main/java/com/sequenceiq/cloudbreak/rotation/secret/vault/VaultRotationContext.java rename to secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/secret/vault/VaultRotationContext.java index c6084367e69..e5a436f6c26 100644 --- a/common/src/main/java/com/sequenceiq/cloudbreak/rotation/secret/vault/VaultRotationContext.java +++ b/secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/secret/vault/VaultRotationContext.java @@ -2,7 +2,7 @@ import java.util.Map; -import com.sequenceiq.cloudbreak.rotation.secret.RotationContext; +import com.sequenceiq.cloudbreak.rotation.common.RotationContext; public class VaultRotationContext extends RotationContext { diff --git a/secret-engine/src/main/java/com/sequenceiq/cloudbreak/service/secret/service/rotation/VaultRotationExecutor.java b/secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/secret/vault/VaultRotationExecutor.java similarity index 88% rename from secret-engine/src/main/java/com/sequenceiq/cloudbreak/service/secret/service/rotation/VaultRotationExecutor.java rename to secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/secret/vault/VaultRotationExecutor.java index 16a47b610d0..9ad07140d4e 100644 --- a/secret-engine/src/main/java/com/sequenceiq/cloudbreak/service/secret/service/rotation/VaultRotationExecutor.java +++ b/secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/secret/vault/VaultRotationExecutor.java @@ -1,4 +1,4 @@ -package com.sequenceiq.cloudbreak.service.secret.service.rotation; +package com.sequenceiq.cloudbreak.rotation.secret.vault; import java.util.Map; @@ -8,11 +8,10 @@ import org.slf4j.LoggerFactory; import org.springframework.stereotype.Component; -import com.sequenceiq.cloudbreak.rotation.secret.AbstractRotationExecutor; -import com.sequenceiq.cloudbreak.rotation.secret.SecretRotationException; -import com.sequenceiq.cloudbreak.rotation.secret.step.CommonSecretRotationStep; -import com.sequenceiq.cloudbreak.rotation.secret.step.SecretRotationStep; -import com.sequenceiq.cloudbreak.rotation.secret.vault.VaultRotationContext; +import com.sequenceiq.cloudbreak.rotation.CommonSecretRotationStep; +import com.sequenceiq.cloudbreak.rotation.SecretRotationStep; +import com.sequenceiq.cloudbreak.rotation.common.SecretRotationException; +import com.sequenceiq.cloudbreak.rotation.executor.AbstractRotationExecutor; import com.sequenceiq.cloudbreak.service.secret.domain.RotationSecret; import com.sequenceiq.cloudbreak.service.secret.service.SecretService; diff --git a/common/src/main/java/com/sequenceiq/cloudbreak/rotation/secret/serialization/SecretRotationEnumSerializationUtil.java b/secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/serialization/SecretRotationEnumSerializationUtil.java similarity index 97% rename from common/src/main/java/com/sequenceiq/cloudbreak/rotation/secret/serialization/SecretRotationEnumSerializationUtil.java rename to secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/serialization/SecretRotationEnumSerializationUtil.java index 9487b066f74..42d239e9ad4 100644 --- a/common/src/main/java/com/sequenceiq/cloudbreak/rotation/secret/serialization/SecretRotationEnumSerializationUtil.java +++ b/secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/serialization/SecretRotationEnumSerializationUtil.java @@ -1,4 +1,4 @@ -package com.sequenceiq.cloudbreak.rotation.secret.serialization; +package com.sequenceiq.cloudbreak.rotation.serialization; import java.io.IOException; import java.util.Arrays; diff --git a/common/src/main/java/com/sequenceiq/cloudbreak/rotation/secret/serialization/SecretRotationStepDeserializer.java b/secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/serialization/SecretRotationStepDeserializer.java similarity index 79% rename from common/src/main/java/com/sequenceiq/cloudbreak/rotation/secret/serialization/SecretRotationStepDeserializer.java rename to secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/serialization/SecretRotationStepDeserializer.java index 4d3ec9d824f..031e0585b36 100644 --- a/common/src/main/java/com/sequenceiq/cloudbreak/rotation/secret/serialization/SecretRotationStepDeserializer.java +++ b/secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/serialization/SecretRotationStepDeserializer.java @@ -1,11 +1,11 @@ -package com.sequenceiq.cloudbreak.rotation.secret.serialization; +package com.sequenceiq.cloudbreak.rotation.serialization; import java.io.IOException; import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.databind.DeserializationContext; import com.fasterxml.jackson.databind.JsonDeserializer; -import com.sequenceiq.cloudbreak.rotation.secret.step.SecretRotationStep; +import com.sequenceiq.cloudbreak.rotation.SecretRotationStep; public class SecretRotationStepDeserializer extends JsonDeserializer> { diff --git a/common/src/main/java/com/sequenceiq/cloudbreak/rotation/secret/serialization/SecretRotationStepSerializer.java b/secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/serialization/SecretRotationStepSerializer.java similarity index 79% rename from common/src/main/java/com/sequenceiq/cloudbreak/rotation/secret/serialization/SecretRotationStepSerializer.java rename to secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/serialization/SecretRotationStepSerializer.java index 91f0c23d9c7..64ce089cdbd 100644 --- a/common/src/main/java/com/sequenceiq/cloudbreak/rotation/secret/serialization/SecretRotationStepSerializer.java +++ b/secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/serialization/SecretRotationStepSerializer.java @@ -1,11 +1,11 @@ -package com.sequenceiq.cloudbreak.rotation.secret.serialization; +package com.sequenceiq.cloudbreak.rotation.serialization; import java.io.IOException; import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.databind.JsonSerializer; import com.fasterxml.jackson.databind.SerializerProvider; -import com.sequenceiq.cloudbreak.rotation.secret.step.SecretRotationStep; +import com.sequenceiq.cloudbreak.rotation.SecretRotationStep; public class SecretRotationStepSerializer extends JsonSerializer> { diff --git a/flow/src/main/java/com/sequenceiq/flow/rotation/service/SecretRotationService.java b/secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/service/SecretRotationService.java similarity index 90% rename from flow/src/main/java/com/sequenceiq/flow/rotation/service/SecretRotationService.java rename to secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/service/SecretRotationService.java index 7e1e71b2df7..6032b78a583 100644 --- a/flow/src/main/java/com/sequenceiq/flow/rotation/service/SecretRotationService.java +++ b/secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/service/SecretRotationService.java @@ -1,4 +1,4 @@ -package com.sequenceiq.flow.rotation.service; +package com.sequenceiq.cloudbreak.rotation.service; import java.util.Collection; import java.util.List; @@ -14,15 +14,15 @@ import com.google.common.base.Joiner; import com.google.common.collect.Lists; -import com.sequenceiq.cloudbreak.rotation.secret.AbstractRotationExecutor; -import com.sequenceiq.cloudbreak.rotation.secret.RotationContext; -import com.sequenceiq.cloudbreak.rotation.secret.RotationContextProvider; -import com.sequenceiq.cloudbreak.rotation.secret.RotationFlowExecutionType; -import com.sequenceiq.cloudbreak.rotation.secret.SecretRotationProgressService; -import com.sequenceiq.cloudbreak.rotation.secret.SecretType; -import com.sequenceiq.cloudbreak.rotation.secret.step.CommonSecretRotationStep; -import com.sequenceiq.cloudbreak.rotation.secret.step.SecretRotationStep; +import com.sequenceiq.cloudbreak.rotation.CommonSecretRotationStep; +import com.sequenceiq.cloudbreak.rotation.RotationFlowExecutionType; +import com.sequenceiq.cloudbreak.rotation.SecretRotationStep; +import com.sequenceiq.cloudbreak.rotation.SecretType; +import com.sequenceiq.cloudbreak.rotation.common.RotationContext; +import com.sequenceiq.cloudbreak.rotation.common.RotationContextProvider; +import com.sequenceiq.cloudbreak.rotation.executor.AbstractRotationExecutor; import com.sequenceiq.cloudbreak.rotation.secret.vault.VaultRotationContext; +import com.sequenceiq.cloudbreak.rotation.service.progress.SecretRotationStepProgressService; import com.sequenceiq.cloudbreak.vault.ThreadBasedVaultReadFieldProvider; @Service @@ -37,7 +37,7 @@ public class SecretRotationService { private Map rotationContextProviderMap; @Inject - private SecretRotationProgressService secretRotationProgressService; + private SecretRotationStepProgressService secretRotationProgressService; public void executePreValidation(SecretType secretType, String resourceId, RotationFlowExecutionType executionType) { if (executionNeeded(executionType, RotationFlowExecutionType.ROTATE, resourceId, secretType)) { diff --git a/flow/src/main/java/com/sequenceiq/flow/rotation/service/SecretRotationValidator.java b/secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/service/SecretRotationValidator.java similarity index 92% rename from flow/src/main/java/com/sequenceiq/flow/rotation/service/SecretRotationValidator.java rename to secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/service/SecretRotationValidator.java index 6561fef98ec..2b144ace1e6 100644 --- a/flow/src/main/java/com/sequenceiq/flow/rotation/service/SecretRotationValidator.java +++ b/secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/service/SecretRotationValidator.java @@ -1,4 +1,4 @@ -package com.sequenceiq.flow.rotation.service; +package com.sequenceiq.cloudbreak.rotation.service; import java.util.Collections; import java.util.List; @@ -8,7 +8,7 @@ import org.springframework.stereotype.Service; import com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException; -import com.sequenceiq.cloudbreak.rotation.secret.SecretType; +import com.sequenceiq.cloudbreak.rotation.SecretType; @Service public class SecretRotationValidator { diff --git a/secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/service/progress/SecretRotationStepProgressService.java b/secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/service/progress/SecretRotationStepProgressService.java new file mode 100644 index 00000000000..401f9b4ed73 --- /dev/null +++ b/secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/service/progress/SecretRotationStepProgressService.java @@ -0,0 +1,42 @@ +package com.sequenceiq.cloudbreak.rotation.service.progress; + +import java.util.Optional; + +import javax.inject.Inject; + +import org.springframework.stereotype.Service; + +import com.sequenceiq.cloudbreak.rotation.RotationFlowExecutionType; +import com.sequenceiq.cloudbreak.rotation.SecretRotationStep; +import com.sequenceiq.cloudbreak.rotation.SecretType; +import com.sequenceiq.cloudbreak.rotation.entity.SecretRotationStepProgress; +import com.sequenceiq.cloudbreak.rotation.repository.SecretRotationStepProgressRepository; + +@Service +public class SecretRotationStepProgressService { + + @Inject + private SecretRotationStepProgressRepository repository; + + public void finished(SecretRotationStepProgress entity) { + entity.setFinished(System.currentTimeMillis()); + repository.save(entity); + } + + public Optional latestStep(String resourceCrn, SecretType secretType, + SecretRotationStep step, RotationFlowExecutionType executionType) { + Optional latestStepProgress = repository.findAllByResourceCrnAndExecutionType(resourceCrn, executionType) + .stream() + .filter(progress -> secretType.equals(progress.getSecretType()) && step.equals(progress.getSecretRotationStep())) + .findFirst(); + if (latestStepProgress.isEmpty()) { + SecretRotationStepProgress progress = new SecretRotationStepProgress(resourceCrn, secretType, step, executionType, System.currentTimeMillis()); + return Optional.of(repository.save(progress)); + } + return latestStepProgress; + } + + public void deleteAll(String resourceCrn, SecretType secretType) { + repository.deleteByResourceCrnAndSecretType(resourceCrn, secretType); + } +} diff --git a/flow/src/main/java/com/sequenceiq/flow/rotation/status/service/DefaultSecretRotationStatusService.java b/secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/service/status/DefaultSecretRotationStatusService.java similarity index 87% rename from flow/src/main/java/com/sequenceiq/flow/rotation/status/service/DefaultSecretRotationStatusService.java rename to secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/service/status/DefaultSecretRotationStatusService.java index df9fb73dc90..c857b7bef63 100644 --- a/flow/src/main/java/com/sequenceiq/flow/rotation/status/service/DefaultSecretRotationStatusService.java +++ b/secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/service/status/DefaultSecretRotationStatusService.java @@ -1,4 +1,4 @@ -package com.sequenceiq.flow.rotation.status.service; +package com.sequenceiq.cloudbreak.rotation.service.status; import org.springframework.stereotype.Component; diff --git a/flow/src/main/java/com/sequenceiq/flow/rotation/status/service/SecretRotationStatusService.java b/secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/service/status/SecretRotationStatusService.java similarity index 78% rename from flow/src/main/java/com/sequenceiq/flow/rotation/status/service/SecretRotationStatusService.java rename to secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/service/status/SecretRotationStatusService.java index 513275fb866..13a737dd067 100644 --- a/flow/src/main/java/com/sequenceiq/flow/rotation/status/service/SecretRotationStatusService.java +++ b/secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/service/status/SecretRotationStatusService.java @@ -1,4 +1,4 @@ -package com.sequenceiq.flow.rotation.status.service; +package com.sequenceiq.cloudbreak.rotation.service.status; public interface SecretRotationStatusService { diff --git a/secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/service/usage/SecretRotationUsageService.java b/secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/service/usage/SecretRotationUsageService.java new file mode 100644 index 00000000000..8ee56a0e7f6 --- /dev/null +++ b/secret-rotation/src/main/java/com/sequenceiq/cloudbreak/rotation/service/usage/SecretRotationUsageService.java @@ -0,0 +1,57 @@ +package com.sequenceiq.cloudbreak.rotation.service.usage; + + +import javax.inject.Inject; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Service; + +import com.sequenceiq.cloudbreak.rotation.RotationFlowExecutionType; +import com.sequenceiq.cloudbreak.rotation.SecretType; +import com.sequenceiq.cloudbreak.usage.service.SecretRotationUsageSenderService; + +@Service +public class SecretRotationUsageService { + + private static final Logger LOGGER = LoggerFactory.getLogger(SecretRotationUsageService.class); + + @Inject + private SecretRotationUsageSenderService secretRotationUsageSenderService; + + public void rotationStarted(SecretType secretType, String resourceCrn, RotationFlowExecutionType executionType) { + if (executionType == null) { + secretRotationUsageSenderService.rotationStarted(secretType.toString(), resourceCrn); + } + } + + public void rotationFinished(SecretType secretType, String resourceCrn, RotationFlowExecutionType executionType) { + if (executionType == null) { + secretRotationUsageSenderService.rotationFinished(secretType.toString(), resourceCrn); + } + } + + public void rotationFailed(SecretType secretType, String resourceCrn, String reason, RotationFlowExecutionType executionType) { + if (executionType == null) { + secretRotationUsageSenderService.rotationFailed(secretType.toString(), resourceCrn, reason); + } + } + + public void rollbackStarted(SecretType secretType, String resourceCrn, RotationFlowExecutionType executionType) { + if (executionType == null) { + secretRotationUsageSenderService.rollbackStarted(secretType.toString(), resourceCrn); + } + } + + public void rollbackFinished(SecretType secretType, String resourceCrn, RotationFlowExecutionType executionType) { + if (executionType == null) { + secretRotationUsageSenderService.rollbackFinished(secretType.toString(), resourceCrn); + } + } + + public void rollbackFailed(SecretType secretType, String resourceCrn, String reason, RotationFlowExecutionType executionType) { + if (executionType == null) { + secretRotationUsageSenderService.rollbackFailed(secretType.toString(), resourceCrn, reason); + } + } +} \ No newline at end of file diff --git a/flow/src/main/resources/schema/flow/20230729163000_CB-21512_add_secretrotationstepprogress.sql b/secret-rotation/src/main/resources/schema/rotation/20230729163000_CB-21512_add_secretrotationstepprogress.sql similarity index 100% rename from flow/src/main/resources/schema/flow/20230729163000_CB-21512_add_secretrotationstepprogress.sql rename to secret-rotation/src/main/resources/schema/rotation/20230729163000_CB-21512_add_secretrotationstepprogress.sql diff --git a/common/src/test/java/com/sequenceiq/cloudbreak/rotation/secret/TestRotationContext.java b/secret-rotation/src/test/java/com/sequenceiq/cloudbreak/rotation/common/TestRotationContext.java similarity index 74% rename from common/src/test/java/com/sequenceiq/cloudbreak/rotation/secret/TestRotationContext.java rename to secret-rotation/src/test/java/com/sequenceiq/cloudbreak/rotation/common/TestRotationContext.java index ae6b665c5a9..e0bdf7cded4 100644 --- a/common/src/test/java/com/sequenceiq/cloudbreak/rotation/secret/TestRotationContext.java +++ b/secret-rotation/src/test/java/com/sequenceiq/cloudbreak/rotation/common/TestRotationContext.java @@ -1,4 +1,4 @@ -package com.sequenceiq.cloudbreak.rotation.secret; +package com.sequenceiq.cloudbreak.rotation.common; public class TestRotationContext extends RotationContext { diff --git a/secret-rotation/src/test/java/com/sequenceiq/cloudbreak/rotation/common/TestSecretRotationStep.java b/secret-rotation/src/test/java/com/sequenceiq/cloudbreak/rotation/common/TestSecretRotationStep.java new file mode 100644 index 00000000000..2ba82657ea9 --- /dev/null +++ b/secret-rotation/src/test/java/com/sequenceiq/cloudbreak/rotation/common/TestSecretRotationStep.java @@ -0,0 +1,8 @@ +package com.sequenceiq.cloudbreak.rotation.common; + +import com.sequenceiq.cloudbreak.rotation.SecretRotationStep; + +public enum TestSecretRotationStep implements SecretRotationStep { + STEP + +} diff --git a/secret-rotation/src/test/java/com/sequenceiq/cloudbreak/rotation/common/TestSecretType.java b/secret-rotation/src/test/java/com/sequenceiq/cloudbreak/rotation/common/TestSecretType.java new file mode 100644 index 00000000000..0f626e24dc4 --- /dev/null +++ b/secret-rotation/src/test/java/com/sequenceiq/cloudbreak/rotation/common/TestSecretType.java @@ -0,0 +1,18 @@ +package com.sequenceiq.cloudbreak.rotation.common; + +import static com.sequenceiq.cloudbreak.rotation.common.TestSecretRotationStep.STEP; + +import java.util.List; + +import com.sequenceiq.cloudbreak.rotation.SecretRotationStep; +import com.sequenceiq.cloudbreak.rotation.SecretType; + +public enum TestSecretType implements SecretType { + TEST, + TEST_2; + + @Override + public List getSteps() { + return List.of(STEP); + } +} diff --git a/common/src/test/java/com/sequenceiq/cloudbreak/rotation/secret/AbstractRotationExecutorTest.java b/secret-rotation/src/test/java/com/sequenceiq/cloudbreak/rotation/executor/AbstractRotationExecutorTest.java similarity index 64% rename from common/src/test/java/com/sequenceiq/cloudbreak/rotation/secret/AbstractRotationExecutorTest.java rename to secret-rotation/src/test/java/com/sequenceiq/cloudbreak/rotation/executor/AbstractRotationExecutorTest.java index 689fcb77a69..67c59ed7bd0 100644 --- a/common/src/test/java/com/sequenceiq/cloudbreak/rotation/secret/AbstractRotationExecutorTest.java +++ b/secret-rotation/src/test/java/com/sequenceiq/cloudbreak/rotation/executor/AbstractRotationExecutorTest.java @@ -1,4 +1,4 @@ -package com.sequenceiq.cloudbreak.rotation.secret; +package com.sequenceiq.cloudbreak.rotation.executor; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.ArgumentMatchers.any; @@ -10,8 +10,6 @@ import java.util.Optional; -import org.apache.commons.lang3.reflect.FieldUtils; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; @@ -19,22 +17,24 @@ import org.mockito.junit.jupiter.MockitoExtension; import com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException; -import com.sequenceiq.cloudbreak.rotation.secret.step.SecretRotationStep; +import com.sequenceiq.cloudbreak.rotation.RotationFlowExecutionType; +import com.sequenceiq.cloudbreak.rotation.SecretRotationStep; +import com.sequenceiq.cloudbreak.rotation.common.RotationContext; +import com.sequenceiq.cloudbreak.rotation.common.SecretRotationException; +import com.sequenceiq.cloudbreak.rotation.common.TestSecretRotationStep; +import com.sequenceiq.cloudbreak.rotation.common.TestSecretType; +import com.sequenceiq.cloudbreak.rotation.entity.SecretRotationStepProgress; +import com.sequenceiq.cloudbreak.rotation.service.progress.SecretRotationStepProgressService; @ExtendWith(MockitoExtension.class) public class AbstractRotationExecutorTest { @Mock - private SecretRotationProgressService secretRotationProgressService; + private SecretRotationStepProgressService secretRotationProgressService; @InjectMocks private TestExecutor underTest; - @BeforeEach - public void mockProgressService() throws IllegalAccessException { - FieldUtils.writeField(underTest, "secretRotationProgressService", Optional.of(secretRotationProgressService), true); - } - @Test public void testRotateWhenNoProgress() { when(secretRotationProgressService.latestStep(any(), any(), any(), any())).thenReturn(Optional.empty()); @@ -42,45 +42,43 @@ public void testRotateWhenNoProgress() { underTest.executeRotate(new RotationContext(""), TestSecretType.TEST); verify(secretRotationProgressService, times(1)).latestStep(any(), any(), any(), any()); - verify(secretRotationProgressService, times(0)).isFinished(any()); verify(secretRotationProgressService, times(0)).finished(any()); } @Test public void testRotateWhenStepOngoing() { - when(secretRotationProgressService.latestStep(any(), any(), any(), any())).thenReturn(Optional.of("anything")); - when(secretRotationProgressService.isFinished(any())).thenReturn(Boolean.FALSE); + when(secretRotationProgressService.latestStep(any(), any(), any(), any())).thenReturn(Optional.of(new SecretRotationStepProgress("", + TestSecretType.TEST, TestSecretRotationStep.STEP, RotationFlowExecutionType.ROTATE, System.currentTimeMillis()))); doNothing().when(secretRotationProgressService).finished(any()); underTest.executeRotate(new RotationContext(""), TestSecretType.TEST); verify(secretRotationProgressService, times(1)).latestStep(any(), any(), any(), any()); - verify(secretRotationProgressService, times(1)).isFinished(any()); verify(secretRotationProgressService, times(1)).finished(any()); } @Test public void testRotateFailureWhenStepOngoing() { - when(secretRotationProgressService.latestStep(any(), any(), any(), any())).thenReturn(Optional.of("anything")); - when(secretRotationProgressService.isFinished(any())).thenReturn(Boolean.FALSE); + when(secretRotationProgressService.latestStep(any(), any(), any(), any())).thenReturn(Optional.of(new SecretRotationStepProgress("", + TestSecretType.TEST, TestSecretRotationStep.STEP, RotationFlowExecutionType.ROTATE, System.currentTimeMillis()))); doNothing().when(secretRotationProgressService).finished(any()); assertThrows(SecretRotationException.class, () -> underTest.executeRotate(new RotationContext(null), TestSecretType.TEST)); verify(secretRotationProgressService, times(1)).latestStep(any(), any(), any(), any()); - verify(secretRotationProgressService, times(1)).isFinished(any()); verify(secretRotationProgressService, times(1)).finished(any()); } @Test public void testRotateWhenStepAlreadyFinished() { - when(secretRotationProgressService.latestStep(any(), any(), any(), any())).thenReturn(Optional.of("anything")); - when(secretRotationProgressService.isFinished(any())).thenReturn(Boolean.TRUE); + SecretRotationStepProgress progress = new SecretRotationStepProgress("", TestSecretType.TEST, TestSecretRotationStep.STEP, + RotationFlowExecutionType.ROTATE, System.currentTimeMillis()); + progress.setFinished(System.currentTimeMillis()); + when(secretRotationProgressService.latestStep(any(), any(), any(), any())).thenReturn(Optional.of(progress)); underTest.executeRotate(new RotationContext(""), TestSecretType.TEST); verify(secretRotationProgressService, times(1)).latestStep(any(), any(), any(), any()); - verify(secretRotationProgressService, times(1)).isFinished(any()); verify(secretRotationProgressService, times(0)).finished(any()); } @@ -112,42 +110,6 @@ public void testPostValidationFailure() { verifyNoInteractions(secretRotationProgressService); } - @Test - public void testRollback() throws IllegalAccessException { - FieldUtils.writeField(underTest, "secretRotationProgressService", Optional.empty(), true); - - underTest.executeRollback(new RotationContext(""), TestSecretType.TEST); - - verifyNoInteractions(secretRotationProgressService); - } - - @Test - public void testRollbackFailure() throws IllegalAccessException { - FieldUtils.writeField(underTest, "secretRotationProgressService", Optional.empty(), true); - - assertThrows(SecretRotationException.class, () -> underTest.executeRollback(new RotationContext(null), TestSecretType.TEST)); - - verifyNoInteractions(secretRotationProgressService); - } - - @Test - public void testFinalize() throws IllegalAccessException { - FieldUtils.writeField(underTest, "secretRotationProgressService", Optional.empty(), true); - - underTest.executeFinalize(new RotationContext(""), TestSecretType.TEST); - - verifyNoInteractions(secretRotationProgressService); - } - - @Test - public void testFinalizeFailure() throws IllegalAccessException { - FieldUtils.writeField(underTest, "secretRotationProgressService", Optional.empty(), true); - - assertThrows(SecretRotationException.class, () -> underTest.executeFinalize(new RotationContext(null), TestSecretType.TEST)); - - verifyNoInteractions(secretRotationProgressService); - } - private static class TestExecutor extends AbstractRotationExecutor { @Override diff --git a/flow/src/test/java/com/sequenceiq/flow/rotation/handler/ExecuteRotationHandlerTest.java b/secret-rotation/src/test/java/com/sequenceiq/cloudbreak/rotation/flow/rotation/handler/ExecuteRotationHandlerTest.java similarity index 73% rename from flow/src/test/java/com/sequenceiq/flow/rotation/handler/ExecuteRotationHandlerTest.java rename to secret-rotation/src/test/java/com/sequenceiq/cloudbreak/rotation/flow/rotation/handler/ExecuteRotationHandlerTest.java index bd28e034014..44239a52c29 100644 --- a/flow/src/test/java/com/sequenceiq/flow/rotation/handler/ExecuteRotationHandlerTest.java +++ b/secret-rotation/src/test/java/com/sequenceiq/cloudbreak/rotation/flow/rotation/handler/ExecuteRotationHandlerTest.java @@ -1,4 +1,4 @@ -package com.sequenceiq.flow.rotation.handler; +package com.sequenceiq.cloudbreak.rotation.flow.rotation.handler; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.ArgumentMatchers.any; @@ -9,8 +9,6 @@ import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; -import java.util.Optional; - import org.apache.commons.lang3.reflect.FieldUtils; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -23,12 +21,12 @@ import com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException; import com.sequenceiq.cloudbreak.eventbus.Event; import com.sequenceiq.cloudbreak.eventbus.EventBus; -import com.sequenceiq.cloudbreak.rotation.secret.SecretType; -import com.sequenceiq.cloudbreak.rotation.secret.usage.SecretRotationUsageProcessor; -import com.sequenceiq.flow.rotation.event.ExecuteRotationFailedEvent; -import com.sequenceiq.flow.rotation.event.ExecuteRotationFinishedEvent; -import com.sequenceiq.flow.rotation.event.ExecuteRotationTriggerEvent; -import com.sequenceiq.flow.rotation.service.SecretRotationService; +import com.sequenceiq.cloudbreak.rotation.SecretType; +import com.sequenceiq.cloudbreak.rotation.flow.rotation.event.ExecuteRotationFailedEvent; +import com.sequenceiq.cloudbreak.rotation.flow.rotation.event.ExecuteRotationFinishedEvent; +import com.sequenceiq.cloudbreak.rotation.flow.rotation.event.ExecuteRotationTriggerEvent; +import com.sequenceiq.cloudbreak.rotation.service.SecretRotationService; +import com.sequenceiq.cloudbreak.rotation.service.usage.SecretRotationUsageService; @ExtendWith(MockitoExtension.class) public class ExecuteRotationHandlerTest { @@ -41,7 +39,7 @@ public class ExecuteRotationHandlerTest { private SecretRotationService secretRotationService; @Mock - private SecretRotationUsageProcessor secretRotationUsageProcessor; + private SecretRotationUsageService secretRotationUsageService; @InjectMocks private ExecuteRotationHandler underTest; @@ -52,7 +50,6 @@ public void setup() throws IllegalAccessException { EventBus eventBus = mock(EventBus.class); doNothing().when(eventBus).notify(anyString(), argumentCaptor.capture()); FieldUtils.writeField(underTest, "eventBus", eventBus, true); - FieldUtils.writeField(underTest, "secretRotationUsageProcessor", Optional.of(secretRotationUsageProcessor), true); } @Test @@ -62,7 +59,7 @@ public void testHandler() { underTest.accept(Event.wrap(getTriggerEvent())); assertEquals(ExecuteRotationFinishedEvent.class, argumentCaptor.getValue().getData().getClass()); - verify(secretRotationUsageProcessor, times(1)).rotationStarted(any(), any(), any()); + verify(secretRotationUsageService, times(1)).rotationStarted(any(), any(), any()); } @Test @@ -72,7 +69,7 @@ public void testHandlerFailure() { underTest.accept(Event.wrap(getTriggerEvent())); assertEquals(ExecuteRotationFailedEvent.class, argumentCaptor.getValue().getData().getClass()); - verify(secretRotationUsageProcessor, times(1)).rotationStarted(any(), any(), any()); + verify(secretRotationUsageService, times(1)).rotationStarted(any(), any(), any()); } private static ExecuteRotationTriggerEvent getTriggerEvent() { diff --git a/flow/src/test/java/com/sequenceiq/flow/rotation/handler/FinalizeRotationHandlerTest.java b/secret-rotation/src/test/java/com/sequenceiq/cloudbreak/rotation/flow/rotation/handler/FinalizeRotationHandlerTest.java similarity index 73% rename from flow/src/test/java/com/sequenceiq/flow/rotation/handler/FinalizeRotationHandlerTest.java rename to secret-rotation/src/test/java/com/sequenceiq/cloudbreak/rotation/flow/rotation/handler/FinalizeRotationHandlerTest.java index bd856c10a88..cd15b354da7 100644 --- a/flow/src/test/java/com/sequenceiq/flow/rotation/handler/FinalizeRotationHandlerTest.java +++ b/secret-rotation/src/test/java/com/sequenceiq/cloudbreak/rotation/flow/rotation/handler/FinalizeRotationHandlerTest.java @@ -1,4 +1,4 @@ -package com.sequenceiq.flow.rotation.handler; +package com.sequenceiq.cloudbreak.rotation.flow.rotation.handler; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.ArgumentMatchers.any; @@ -10,8 +10,6 @@ import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; -import java.util.Optional; - import org.apache.commons.lang3.reflect.FieldUtils; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -24,12 +22,12 @@ import com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException; import com.sequenceiq.cloudbreak.eventbus.Event; import com.sequenceiq.cloudbreak.eventbus.EventBus; -import com.sequenceiq.cloudbreak.rotation.secret.SecretType; -import com.sequenceiq.cloudbreak.rotation.secret.usage.SecretRotationUsageProcessor; -import com.sequenceiq.flow.rotation.event.FinalizeRotationSuccessEvent; -import com.sequenceiq.flow.rotation.event.FinalizeRotationTriggerEvent; -import com.sequenceiq.flow.rotation.event.RotationFailedEvent; -import com.sequenceiq.flow.rotation.service.SecretRotationService; +import com.sequenceiq.cloudbreak.rotation.SecretType; +import com.sequenceiq.cloudbreak.rotation.flow.rotation.event.FinalizeRotationSuccessEvent; +import com.sequenceiq.cloudbreak.rotation.flow.rotation.event.FinalizeRotationTriggerEvent; +import com.sequenceiq.cloudbreak.rotation.flow.rotation.event.RotationFailedEvent; +import com.sequenceiq.cloudbreak.rotation.service.SecretRotationService; +import com.sequenceiq.cloudbreak.rotation.service.usage.SecretRotationUsageService; @ExtendWith(MockitoExtension.class) public class FinalizeRotationHandlerTest { @@ -42,7 +40,7 @@ public class FinalizeRotationHandlerTest { private SecretRotationService secretRotationService; @Mock - private SecretRotationUsageProcessor secretRotationUsageProcessor; + private SecretRotationUsageService secretRotationUsageService; @InjectMocks private FinalizeRotationHandler underTest; @@ -53,7 +51,6 @@ public void setup() throws IllegalAccessException { EventBus eventBus = mock(EventBus.class); doNothing().when(eventBus).notify(anyString(), argumentCaptor.capture()); FieldUtils.writeField(underTest, "eventBus", eventBus, true); - FieldUtils.writeField(underTest, "secretRotationUsageProcessor", Optional.of(secretRotationUsageProcessor), true); } @Test @@ -63,7 +60,7 @@ public void testHandler() { underTest.accept(Event.wrap(getTriggerEvent())); assertEquals(FinalizeRotationSuccessEvent.class, argumentCaptor.getValue().getData().getClass()); - verify(secretRotationUsageProcessor, times(1)).rotationFinished(any(), any(), any()); + verify(secretRotationUsageService, times(1)).rotationFinished(any(), any(), any()); } @Test @@ -73,7 +70,7 @@ public void testHandlerFailure() { underTest.accept(Event.wrap(getTriggerEvent())); assertEquals(RotationFailedEvent.class, argumentCaptor.getValue().getData().getClass()); - verify(secretRotationUsageProcessor, never()).rotationFinished(any(), any(), any()); + verify(secretRotationUsageService, never()).rotationFinished(any(), any(), any()); } private static FinalizeRotationTriggerEvent getTriggerEvent() { diff --git a/flow/src/test/java/com/sequenceiq/flow/rotation/handler/PreValidateRotationHandlerTest.java b/secret-rotation/src/test/java/com/sequenceiq/cloudbreak/rotation/flow/rotation/handler/PreValidateRotationHandlerTest.java similarity index 84% rename from flow/src/test/java/com/sequenceiq/flow/rotation/handler/PreValidateRotationHandlerTest.java rename to secret-rotation/src/test/java/com/sequenceiq/cloudbreak/rotation/flow/rotation/handler/PreValidateRotationHandlerTest.java index 4413e77d998..d70f5df6167 100644 --- a/flow/src/test/java/com/sequenceiq/flow/rotation/handler/PreValidateRotationHandlerTest.java +++ b/secret-rotation/src/test/java/com/sequenceiq/cloudbreak/rotation/flow/rotation/handler/PreValidateRotationHandlerTest.java @@ -1,4 +1,4 @@ -package com.sequenceiq.flow.rotation.handler; +package com.sequenceiq.cloudbreak.rotation.flow.rotation.handler; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.ArgumentMatchers.any; @@ -19,10 +19,10 @@ import com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException; import com.sequenceiq.cloudbreak.eventbus.Event; import com.sequenceiq.cloudbreak.eventbus.EventBus; -import com.sequenceiq.flow.rotation.event.PreValidateRotationFinishedEvent; -import com.sequenceiq.flow.rotation.event.PreValidateRotationTriggerEvent; -import com.sequenceiq.flow.rotation.event.RotationFailedEvent; -import com.sequenceiq.flow.rotation.service.SecretRotationService; +import com.sequenceiq.cloudbreak.rotation.flow.rotation.event.PreValidateRotationFinishedEvent; +import com.sequenceiq.cloudbreak.rotation.flow.rotation.event.PreValidateRotationTriggerEvent; +import com.sequenceiq.cloudbreak.rotation.flow.rotation.event.RotationFailedEvent; +import com.sequenceiq.cloudbreak.rotation.service.SecretRotationService; @ExtendWith(MockitoExtension.class) public class PreValidateRotationHandlerTest { diff --git a/flow/src/test/java/com/sequenceiq/flow/rotation/handler/RollbackRotationHandlerTest.java b/secret-rotation/src/test/java/com/sequenceiq/cloudbreak/rotation/flow/rotation/handler/RollbackRotationHandlerTest.java similarity index 70% rename from flow/src/test/java/com/sequenceiq/flow/rotation/handler/RollbackRotationHandlerTest.java rename to secret-rotation/src/test/java/com/sequenceiq/cloudbreak/rotation/flow/rotation/handler/RollbackRotationHandlerTest.java index 5609a3b08ff..c442989e668 100644 --- a/flow/src/test/java/com/sequenceiq/flow/rotation/handler/RollbackRotationHandlerTest.java +++ b/secret-rotation/src/test/java/com/sequenceiq/cloudbreak/rotation/flow/rotation/handler/RollbackRotationHandlerTest.java @@ -1,4 +1,4 @@ -package com.sequenceiq.flow.rotation.handler; +package com.sequenceiq.cloudbreak.rotation.flow.rotation.handler; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.ArgumentMatchers.any; @@ -9,8 +9,6 @@ import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; -import java.util.Optional; - import org.apache.commons.lang3.reflect.FieldUtils; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -23,11 +21,11 @@ import com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException; import com.sequenceiq.cloudbreak.eventbus.Event; import com.sequenceiq.cloudbreak.eventbus.EventBus; -import com.sequenceiq.cloudbreak.rotation.secret.SecretType; -import com.sequenceiq.cloudbreak.rotation.secret.usage.SecretRotationUsageProcessor; -import com.sequenceiq.flow.rotation.event.RollbackRotationTriggerEvent; -import com.sequenceiq.flow.rotation.event.RotationFailedEvent; -import com.sequenceiq.flow.rotation.service.SecretRotationService; +import com.sequenceiq.cloudbreak.rotation.SecretType; +import com.sequenceiq.cloudbreak.rotation.flow.rotation.event.RollbackRotationTriggerEvent; +import com.sequenceiq.cloudbreak.rotation.flow.rotation.event.RotationFailedEvent; +import com.sequenceiq.cloudbreak.rotation.service.SecretRotationService; +import com.sequenceiq.cloudbreak.rotation.service.usage.SecretRotationUsageService; @ExtendWith(MockitoExtension.class) public class RollbackRotationHandlerTest { @@ -40,7 +38,7 @@ public class RollbackRotationHandlerTest { private SecretRotationService secretRotationService; @Mock - private SecretRotationUsageProcessor secretRotationUsageProcessor; + private SecretRotationUsageService secretRotationUsageService; @InjectMocks private RollbackRotationHandler underTest; @@ -51,7 +49,6 @@ public void setup() throws IllegalAccessException { EventBus eventBus = mock(EventBus.class); doNothing().when(eventBus).notify(anyString(), argumentCaptor.capture()); FieldUtils.writeField(underTest, "eventBus", eventBus, true); - FieldUtils.writeField(underTest, "secretRotationUsageProcessor", Optional.of(secretRotationUsageProcessor), true); } @Test @@ -61,8 +58,8 @@ public void testHandler() { underTest.accept(Event.wrap(getTriggerEvent())); assertEquals(RotationFailedEvent.class, argumentCaptor.getValue().getData().getClass()); - verify(secretRotationUsageProcessor, times(1)).rollbackStarted(any(), any(), any()); - verify(secretRotationUsageProcessor, times(1)).rollbackFinished(any(), any(), any()); + verify(secretRotationUsageService, times(1)).rollbackStarted(any(), any(), any()); + verify(secretRotationUsageService, times(1)).rollbackFinished(any(), any(), any()); } @Test @@ -72,8 +69,8 @@ public void testHandlerFailure() { underTest.accept(Event.wrap(getTriggerEvent())); assertEquals(RotationFailedEvent.class, argumentCaptor.getValue().getData().getClass()); - verify(secretRotationUsageProcessor, times(1)).rollbackStarted(any(), any(), any()); - verify(secretRotationUsageProcessor, times(1)).rollbackFailed(any(), any(), any(), any()); + verify(secretRotationUsageService, times(1)).rollbackStarted(any(), any(), any()); + verify(secretRotationUsageService, times(1)).rollbackFailed(any(), any(), any(), any()); } private static RollbackRotationTriggerEvent getTriggerEvent() { diff --git a/common/src/test/java/com/sequenceiq/cloudbreak/rotation/secret/CustomJobExecutorTest.java b/secret-rotation/src/test/java/com/sequenceiq/cloudbreak/rotation/secret/custom/CustomJobExecutorTest.java similarity index 87% rename from common/src/test/java/com/sequenceiq/cloudbreak/rotation/secret/CustomJobExecutorTest.java rename to secret-rotation/src/test/java/com/sequenceiq/cloudbreak/rotation/secret/custom/CustomJobExecutorTest.java index 31b4a9c93a3..8ebee227d91 100644 --- a/common/src/test/java/com/sequenceiq/cloudbreak/rotation/secret/CustomJobExecutorTest.java +++ b/secret-rotation/src/test/java/com/sequenceiq/cloudbreak/rotation/secret/custom/CustomJobExecutorTest.java @@ -1,4 +1,4 @@ -package com.sequenceiq.cloudbreak.rotation.secret; +package com.sequenceiq.cloudbreak.rotation.secret.custom; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.ArgumentMatchers.any; @@ -9,7 +9,6 @@ import java.util.Optional; -import org.apache.commons.lang3.reflect.FieldUtils; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -17,7 +16,9 @@ import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; -import com.sequenceiq.cloudbreak.rotation.secret.context.CustomJobRotationContext; +import com.sequenceiq.cloudbreak.rotation.common.RotationContext; +import com.sequenceiq.cloudbreak.rotation.common.SecretRotationException; +import com.sequenceiq.cloudbreak.rotation.service.progress.SecretRotationStepProgressService; @ExtendWith(MockitoExtension.class) class CustomJobExecutorTest { @@ -32,14 +33,13 @@ class CustomJobExecutorTest { private Runnable finalizeCustomJob; @Mock - private SecretRotationProgressService secretRotationProgressService; + private SecretRotationStepProgressService secretRotationProgressService; @InjectMocks private CustomJobExecutor underTest; @BeforeEach - public void mockProgressService() throws IllegalAccessException { - FieldUtils.writeField(underTest, "secretRotationProgressService", Optional.of(secretRotationProgressService), true); + public void mockProgressService() { lenient().when(secretRotationProgressService.latestStep(any(), any(), any(), any())).thenReturn(Optional.empty()); } diff --git a/secret-engine/src/test/java/com/sequenceiq/cloudbreak/service/secret/service/rotation/VaultRotationExecutorTest.java b/secret-rotation/src/test/java/com/sequenceiq/cloudbreak/rotation/secret/vault/VaultRotationExecutorTest.java similarity index 89% rename from secret-engine/src/test/java/com/sequenceiq/cloudbreak/service/secret/service/rotation/VaultRotationExecutorTest.java rename to secret-rotation/src/test/java/com/sequenceiq/cloudbreak/rotation/secret/vault/VaultRotationExecutorTest.java index f0b2622f3be..e10976ea05e 100644 --- a/secret-engine/src/test/java/com/sequenceiq/cloudbreak/service/secret/service/rotation/VaultRotationExecutorTest.java +++ b/secret-rotation/src/test/java/com/sequenceiq/cloudbreak/rotation/secret/vault/VaultRotationExecutorTest.java @@ -1,4 +1,4 @@ -package com.sequenceiq.cloudbreak.service.secret.service.rotation; +package com.sequenceiq.cloudbreak.rotation.secret.vault; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.ArgumentMatchers.any; @@ -12,7 +12,6 @@ import java.util.Map; import java.util.Optional; -import org.apache.commons.lang3.reflect.FieldUtils; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -20,9 +19,8 @@ import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; -import com.sequenceiq.cloudbreak.rotation.secret.SecretRotationException; -import com.sequenceiq.cloudbreak.rotation.secret.SecretRotationProgressService; -import com.sequenceiq.cloudbreak.rotation.secret.vault.VaultRotationContext; +import com.sequenceiq.cloudbreak.rotation.common.SecretRotationException; +import com.sequenceiq.cloudbreak.rotation.service.progress.SecretRotationStepProgressService; import com.sequenceiq.cloudbreak.service.secret.domain.RotationSecret; import com.sequenceiq.cloudbreak.service.secret.service.SecretService; @@ -33,14 +31,13 @@ public class VaultRotationExecutorTest { private SecretService secretService; @Mock - private SecretRotationProgressService secretRotationProgressService; + private SecretRotationStepProgressService secretRotationProgressService; @InjectMocks private VaultRotationExecutor underTest; @BeforeEach - public void mockProgressService() throws IllegalAccessException { - FieldUtils.writeField(underTest, "secretRotationProgressService", Optional.of(secretRotationProgressService), true); + public void mockProgressService() { lenient().when(secretRotationProgressService.latestStep(any(), any(), any(), any())).thenReturn(Optional.empty()); } diff --git a/flow/src/test/java/com/sequenceiq/flow/rotation/service/SecretRotationServiceTest.java b/secret-rotation/src/test/java/com/sequenceiq/cloudbreak/rotation/service/SecretRotationServiceTest.java similarity index 85% rename from flow/src/test/java/com/sequenceiq/flow/rotation/service/SecretRotationServiceTest.java rename to secret-rotation/src/test/java/com/sequenceiq/cloudbreak/rotation/service/SecretRotationServiceTest.java index d6cd3e45002..89d0aacb3c6 100644 --- a/flow/src/test/java/com/sequenceiq/flow/rotation/service/SecretRotationServiceTest.java +++ b/secret-rotation/src/test/java/com/sequenceiq/cloudbreak/rotation/service/SecretRotationServiceTest.java @@ -1,6 +1,6 @@ -package com.sequenceiq.flow.rotation.service; +package com.sequenceiq.cloudbreak.rotation.service; -import static com.sequenceiq.cloudbreak.rotation.secret.TestSecretRotationStep.STEP; +import static com.sequenceiq.cloudbreak.rotation.common.TestSecretRotationStep.STEP; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyString; @@ -22,14 +22,15 @@ import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; -import com.sequenceiq.cloudbreak.rotation.secret.AbstractRotationExecutor; -import com.sequenceiq.cloudbreak.rotation.secret.RotationContext; -import com.sequenceiq.cloudbreak.rotation.secret.RotationContextProvider; -import com.sequenceiq.cloudbreak.rotation.secret.RotationFlowExecutionType; -import com.sequenceiq.cloudbreak.rotation.secret.SecretRotationException; -import com.sequenceiq.cloudbreak.rotation.secret.TestRotationContext; -import com.sequenceiq.cloudbreak.rotation.secret.TestSecretType; -import com.sequenceiq.cloudbreak.rotation.secret.step.SecretRotationStep; +import com.sequenceiq.cloudbreak.rotation.RotationFlowExecutionType; +import com.sequenceiq.cloudbreak.rotation.SecretRotationStep; +import com.sequenceiq.cloudbreak.rotation.common.RotationContext; +import com.sequenceiq.cloudbreak.rotation.common.RotationContextProvider; +import com.sequenceiq.cloudbreak.rotation.common.SecretRotationException; +import com.sequenceiq.cloudbreak.rotation.common.TestRotationContext; +import com.sequenceiq.cloudbreak.rotation.common.TestSecretType; +import com.sequenceiq.cloudbreak.rotation.executor.AbstractRotationExecutor; +import com.sequenceiq.cloudbreak.rotation.service.progress.SecretRotationStepProgressService; @ExtendWith(MockitoExtension.class) public class SecretRotationServiceTest { diff --git a/flow/src/test/java/com/sequenceiq/flow/rotation/service/SecretRotationValidatorTest.java b/secret-rotation/src/test/java/com/sequenceiq/cloudbreak/rotation/service/SecretRotationValidatorTest.java similarity index 85% rename from flow/src/test/java/com/sequenceiq/flow/rotation/service/SecretRotationValidatorTest.java rename to secret-rotation/src/test/java/com/sequenceiq/cloudbreak/rotation/service/SecretRotationValidatorTest.java index eeb49f264e2..c6a4cf98b70 100644 --- a/flow/src/test/java/com/sequenceiq/flow/rotation/service/SecretRotationValidatorTest.java +++ b/secret-rotation/src/test/java/com/sequenceiq/cloudbreak/rotation/service/SecretRotationValidatorTest.java @@ -1,7 +1,7 @@ -package com.sequenceiq.flow.rotation.service; +package com.sequenceiq.cloudbreak.rotation.service; -import static com.sequenceiq.cloudbreak.rotation.secret.TestSecretType.TEST; -import static com.sequenceiq.cloudbreak.rotation.secret.TestSecretType.TEST_2; +import static com.sequenceiq.cloudbreak.rotation.common.TestSecretType.TEST; +import static com.sequenceiq.cloudbreak.rotation.common.TestSecretType.TEST_2; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; @@ -14,8 +14,8 @@ import org.mockito.junit.jupiter.MockitoExtension; import com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException; -import com.sequenceiq.cloudbreak.rotation.secret.SecretType; -import com.sequenceiq.cloudbreak.rotation.secret.TestSecretType; +import com.sequenceiq.cloudbreak.rotation.SecretType; +import com.sequenceiq.cloudbreak.rotation.common.TestSecretType; @ExtendWith(MockitoExtension.class) class SecretRotationValidatorTest { diff --git a/flow/src/test/java/com/sequenceiq/flow/rotation/service/SecretRotationStepProgressServiceTest.java b/secret-rotation/src/test/java/com/sequenceiq/cloudbreak/rotation/service/progress/SecretRotationStepProgressServiceTest.java similarity index 71% rename from flow/src/test/java/com/sequenceiq/flow/rotation/service/SecretRotationStepProgressServiceTest.java rename to secret-rotation/src/test/java/com/sequenceiq/cloudbreak/rotation/service/progress/SecretRotationStepProgressServiceTest.java index f42cc1ffccf..4a2647f09e4 100644 --- a/flow/src/test/java/com/sequenceiq/flow/rotation/service/SecretRotationStepProgressServiceTest.java +++ b/secret-rotation/src/test/java/com/sequenceiq/cloudbreak/rotation/service/progress/SecretRotationStepProgressServiceTest.java @@ -1,4 +1,4 @@ -package com.sequenceiq.flow.rotation.service; +package com.sequenceiq.cloudbreak.rotation.service.progress; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.ArgumentMatchers.any; @@ -6,22 +6,19 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -import java.util.Optional; import java.util.Set; -import org.apache.commons.lang3.reflect.FieldUtils; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; -import com.sequenceiq.cloudbreak.rotation.secret.RotationFlowExecutionType; -import com.sequenceiq.cloudbreak.rotation.secret.TestSecretRotationStep; -import com.sequenceiq.cloudbreak.rotation.secret.TestSecretType; -import com.sequenceiq.flow.rotation.entity.SecretRotationStepProgress; -import com.sequenceiq.flow.rotation.repository.SecretRotationStepProgressRepository; +import com.sequenceiq.cloudbreak.rotation.RotationFlowExecutionType; +import com.sequenceiq.cloudbreak.rotation.common.TestSecretRotationStep; +import com.sequenceiq.cloudbreak.rotation.common.TestSecretType; +import com.sequenceiq.cloudbreak.rotation.entity.SecretRotationStepProgress; +import com.sequenceiq.cloudbreak.rotation.repository.SecretRotationStepProgressRepository; @ExtendWith(MockitoExtension.class) public class SecretRotationStepProgressServiceTest { @@ -32,11 +29,6 @@ public class SecretRotationStepProgressServiceTest { @InjectMocks private SecretRotationStepProgressService underTest; - @BeforeEach - public void mockRepository() throws IllegalAccessException { - FieldUtils.writeField(underTest, "repository", Optional.of(repository), true); - } - @Test public void testWhenNoProgress() { when(repository.findAllByResourceCrnAndExecutionType(any(), any())).thenReturn(Set.of()); diff --git a/secret-rotation/src/test/java/com/sequenceiq/cloudbreak/rotation/service/usage/SecretRotationUsageServiceTest.java b/secret-rotation/src/test/java/com/sequenceiq/cloudbreak/rotation/service/usage/SecretRotationUsageServiceTest.java new file mode 100644 index 00000000000..a59423fc2d6 --- /dev/null +++ b/secret-rotation/src/test/java/com/sequenceiq/cloudbreak/rotation/service/usage/SecretRotationUsageServiceTest.java @@ -0,0 +1,144 @@ +package com.sequenceiq.cloudbreak.rotation.service.usage; + +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoInteractions; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.junit.jupiter.MockitoExtension; + +import com.sequenceiq.cloudbreak.auth.ThreadBasedUserCrnProvider; +import com.sequenceiq.cloudbreak.rotation.RotationFlowExecutionType; +import com.sequenceiq.cloudbreak.rotation.SecretType; +import com.sequenceiq.cloudbreak.usage.service.SecretRotationUsageSenderService; + +@ExtendWith(MockitoExtension.class) +public class SecretRotationUsageServiceTest { + + private static final SecretType SECRET_TYPE = Mockito.mock(SecretType.class); + + private static final String RESOURCE_CRN = "resourceCrn"; + + private static final String REASON = "reason"; + + private static final String USER_CRN = "crn:cdp:iam:us-west-1:1234:user:5678"; + + @Mock + private SecretRotationUsageSenderService secretRotationUsageSenderService; + + @InjectMocks + private SecretRotationUsageService underTest; + + @Test + public void testRotationStartedWhenErrorOccurs() { + assertThrows(NullPointerException.class, () -> underTest.rotationStarted(null, null, null)); + verifyNoInteractions(secretRotationUsageSenderService); + } + + @Test + public void testRotationFinishedWhenErrorOccurs() { + assertThrows(NullPointerException.class, () -> underTest.rotationFinished(null, null, null)); + verifyNoInteractions(secretRotationUsageSenderService); + } + + @Test + public void testRotationFailedWhenErrorOccurs() { + assertThrows(NullPointerException.class, () -> underTest.rotationFailed(null, null, null, null)); + verifyNoInteractions(secretRotationUsageSenderService); + } + + @Test + public void testRollbackStartedWhenErrorOccurs() { + assertThrows(NullPointerException.class, () -> underTest.rollbackStarted(null, null, null)); + verifyNoInteractions(secretRotationUsageSenderService); + } + + @Test + public void testRollbackFinishedWhenErrorOccurs() { + assertThrows(NullPointerException.class, () -> underTest.rollbackFinished(null, null, null)); + verifyNoInteractions(secretRotationUsageSenderService); + } + + @Test + public void testRollbackFailedWhenErrorOccurs() { + assertThrows(NullPointerException.class, () -> underTest.rollbackFailed(null, null, null, null)); + verifyNoInteractions(secretRotationUsageSenderService); + } + + @Test + public void testRotationStartedWhenExecutionTypeIsNotNull() { + underTest.rotationStarted(SECRET_TYPE, RESOURCE_CRN, RotationFlowExecutionType.ROTATE); + verifyNoInteractions(secretRotationUsageSenderService); + } + + @Test + public void testRotationFinishedWhenExecutionTypeIsNotNull() { + underTest.rotationFinished(SECRET_TYPE, RESOURCE_CRN, RotationFlowExecutionType.ROTATE); + verifyNoInteractions(secretRotationUsageSenderService); + } + + @Test + public void testRotationFailedWhenExecutionTypeIsNotNull() { + underTest.rotationFailed(SECRET_TYPE, RESOURCE_CRN, null, RotationFlowExecutionType.ROTATE); + verifyNoInteractions(secretRotationUsageSenderService); + } + + @Test + public void testRollbackStartedWhenExecutionTypeIsNotNull() { + underTest.rollbackStarted(SECRET_TYPE, RESOURCE_CRN, RotationFlowExecutionType.ROTATE); + verifyNoInteractions(secretRotationUsageSenderService); + } + + @Test + public void testRollbackFinishedWhenExecutionTypeIsNotNull() { + underTest.rollbackFinished(SECRET_TYPE, RESOURCE_CRN, RotationFlowExecutionType.ROTATE); + verifyNoInteractions(secretRotationUsageSenderService); + } + + @Test + public void testRollbackFailedWhenExecutionTypeIsNotNull() { + underTest.rollbackFailed(SECRET_TYPE, RESOURCE_CRN, null, RotationFlowExecutionType.ROTATE); + verifyNoInteractions(secretRotationUsageSenderService); + } + + @Test + public void testRotationStarted() { + ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.rotationStarted(SECRET_TYPE, RESOURCE_CRN, null)); + verify(secretRotationUsageSenderService).rotationStarted(eq(SECRET_TYPE.toString()), eq(RESOURCE_CRN)); + } + + @Test + public void testRotationFinished() { + ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.rotationFinished(SECRET_TYPE, RESOURCE_CRN, null)); + verify(secretRotationUsageSenderService).rotationFinished(eq(SECRET_TYPE.toString()), eq(RESOURCE_CRN)); + } + + @Test + public void testRotationFailed() { + ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.rotationFailed(SECRET_TYPE, RESOURCE_CRN, REASON, null)); + verify(secretRotationUsageSenderService).rotationFailed(eq(SECRET_TYPE.toString()), eq(RESOURCE_CRN), eq(REASON)); + } + + @Test + public void testRollbackStarted() { + ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.rollbackStarted(SECRET_TYPE, RESOURCE_CRN, null)); + verify(secretRotationUsageSenderService).rollbackStarted(eq(SECRET_TYPE.toString()), eq(RESOURCE_CRN)); + } + + @Test + public void testRollbackFinished() { + ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.rollbackFinished(SECRET_TYPE, RESOURCE_CRN, null)); + verify(secretRotationUsageSenderService).rollbackFinished(eq(SECRET_TYPE.toString()), eq(RESOURCE_CRN)); + } + + @Test + public void testRollbackFailed() { + ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.rollbackFailed(SECRET_TYPE, RESOURCE_CRN, REASON, null)); + verify(secretRotationUsageSenderService).rollbackFailed(eq(SECRET_TYPE.toString()), eq(RESOURCE_CRN), eq(REASON)); + } +} \ No newline at end of file diff --git a/settings.gradle b/settings.gradle index 700bddb232c..d916cffc044 100644 --- a/settings.gradle +++ b/settings.gradle @@ -82,4 +82,6 @@ include 'cloud-consumption-api' include 'auth-distributor-connector' include 'sdx-connector' include 'wiam-connector' +include 'secret-rotation-api' +include 'secret-rotation' diff --git a/usage-collection/src/main/java/com/sequenceiq/cloudbreak/usage/service/SecretRotationUsageSenderService.java b/usage-collection/src/main/java/com/sequenceiq/cloudbreak/usage/service/SecretRotationUsageSenderService.java new file mode 100644 index 00000000000..78cf8e109d0 --- /dev/null +++ b/usage-collection/src/main/java/com/sequenceiq/cloudbreak/usage/service/SecretRotationUsageSenderService.java @@ -0,0 +1,61 @@ +package com.sequenceiq.cloudbreak.usage.service; + +import static com.cloudera.thunderhead.service.common.usage.UsageProto.CDPSecretRotationEvent; +import static com.cloudera.thunderhead.service.common.usage.UsageProto.CDPSecretRotationStatus; + +import javax.inject.Inject; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Service; + +import com.sequenceiq.cloudbreak.auth.ThreadBasedUserCrnProvider; +import com.sequenceiq.cloudbreak.usage.UsageReporter; + +@Service +public class SecretRotationUsageSenderService { + + private static final Logger LOGGER = LoggerFactory.getLogger(SecretRotationUsageSenderService.class); + + @Inject + private UsageReporter usageReporter; + + public void rotationStarted(String secretType, String resourceCrn) { + sendUsageReport(secretType, resourceCrn, null, CDPSecretRotationStatus.Value.STARTED); + } + + public void rotationFinished(String secretType, String resourceCrn) { + sendUsageReport(secretType, resourceCrn, null, CDPSecretRotationStatus.Value.FINISHED); + } + + public void rotationFailed(String secretType, String resourceCrn, String reason) { + sendUsageReport(secretType, resourceCrn, reason, CDPSecretRotationStatus.Value.FAILED); + } + + public void rollbackStarted(String secretType, String resourceCrn) { + sendUsageReport(secretType, resourceCrn, null, CDPSecretRotationStatus.Value.ROLLBACK_STARTED); + } + + public void rollbackFinished(String secretType, String resourceCrn) { + sendUsageReport(secretType, resourceCrn, null, CDPSecretRotationStatus.Value.ROLLBACK_FINISHED); + } + + public void rollbackFailed(String secretType, String resourceCrn, String reason) { + sendUsageReport(secretType, resourceCrn, reason, CDPSecretRotationStatus.Value.ROLLBACK_FAILED); + } + + private void sendUsageReport(String secretType, String resourceCrn, String reason, CDPSecretRotationStatus.Value status) { + try { + LOGGER.debug("Send secret rotation usage report for secretType: {}, status: {}, reason: {}", secretType, status, reason); + usageReporter.cdpSecretRotationEvent(CDPSecretRotationEvent.newBuilder() + .setAccountId(ThreadBasedUserCrnProvider.getAccountId()) + .setSecretType(secretType.toString()) + .setResourceCrn(resourceCrn) + .setReason(reason == null ? "" : reason) + .setStatus(status) + .build()); + } catch (Exception e) { + LOGGER.error("Couldn't send usage report about secret rotation with secret type: {}, status: {}", secretType, status, e); + } + } +} \ No newline at end of file diff --git a/usage-collection/src/main/java/com/sequenceiq/cloudbreak/usage/service/SecretRotationUsageService.java b/usage-collection/src/main/java/com/sequenceiq/cloudbreak/usage/service/SecretRotationUsageService.java deleted file mode 100644 index b41bfddd792..00000000000 --- a/usage-collection/src/main/java/com/sequenceiq/cloudbreak/usage/service/SecretRotationUsageService.java +++ /dev/null @@ -1,82 +0,0 @@ -package com.sequenceiq.cloudbreak.usage.service; - -import static com.cloudera.thunderhead.service.common.usage.UsageProto.CDPSecretRotationEvent; -import static com.cloudera.thunderhead.service.common.usage.UsageProto.CDPSecretRotationStatus; - -import javax.inject.Inject; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.stereotype.Service; - -import com.sequenceiq.cloudbreak.auth.ThreadBasedUserCrnProvider; -import com.sequenceiq.cloudbreak.rotation.secret.RotationFlowExecutionType; -import com.sequenceiq.cloudbreak.rotation.secret.SecretType; -import com.sequenceiq.cloudbreak.rotation.secret.usage.SecretRotationUsageProcessor; -import com.sequenceiq.cloudbreak.usage.UsageReporter; - -@Service -public class SecretRotationUsageService implements SecretRotationUsageProcessor { - - private static final Logger LOGGER = LoggerFactory.getLogger(SecretRotationUsageService.class); - - @Inject - private UsageReporter usageReporter; - - @Override - public void rotationStarted(SecretType secretType, String resourceCrn, RotationFlowExecutionType executionType) { - if (executionType == null) { - sendUsageReport(secretType, resourceCrn, null, CDPSecretRotationStatus.Value.STARTED); - } - } - - @Override - public void rotationFinished(SecretType secretType, String resourceCrn, RotationFlowExecutionType executionType) { - if (executionType == null) { - sendUsageReport(secretType, resourceCrn, null, CDPSecretRotationStatus.Value.FINISHED); - } - } - - @Override - public void rotationFailed(SecretType secretType, String resourceCrn, String reason, RotationFlowExecutionType executionType) { - if (executionType == null) { - sendUsageReport(secretType, resourceCrn, reason, CDPSecretRotationStatus.Value.FAILED); - } - } - - @Override - public void rollbackStarted(SecretType secretType, String resourceCrn, RotationFlowExecutionType executionType) { - if (executionType == null) { - sendUsageReport(secretType, resourceCrn, null, CDPSecretRotationStatus.Value.ROLLBACK_STARTED); - } - } - - @Override - public void rollbackFinished(SecretType secretType, String resourceCrn, RotationFlowExecutionType executionType) { - if (executionType == null) { - sendUsageReport(secretType, resourceCrn, null, CDPSecretRotationStatus.Value.ROLLBACK_FINISHED); - } - } - - @Override - public void rollbackFailed(SecretType secretType, String resourceCrn, String reason, RotationFlowExecutionType executionType) { - if (executionType == null) { - sendUsageReport(secretType, resourceCrn, reason, CDPSecretRotationStatus.Value.ROLLBACK_FAILED); - } - } - - private void sendUsageReport(SecretType secretType, String resourceCrn, String reason, CDPSecretRotationStatus.Value status) { - try { - LOGGER.debug("Send secret rotation usage report for secretType: {}, status: {}, reason: {}", secretType, status, reason); - usageReporter.cdpSecretRotationEvent(CDPSecretRotationEvent.newBuilder() - .setAccountId(ThreadBasedUserCrnProvider.getAccountId()) - .setSecretType(secretType.toString()) - .setResourceCrn(resourceCrn) - .setReason(reason == null ? "" : reason) - .setStatus(status) - .build()); - } catch (Exception e) { - LOGGER.error("Couldn't send usage report about secret rotation with secret type: {}, status: {}", secretType, status, e); - } - } -} diff --git a/usage-collection/src/test/java/com/sequenceiq/cloudbreak/usage/service/SecretRotationUsageServiceTest.java b/usage-collection/src/test/java/com/sequenceiq/cloudbreak/usage/service/SecretRotationUsageSenderServiceTest.java similarity index 78% rename from usage-collection/src/test/java/com/sequenceiq/cloudbreak/usage/service/SecretRotationUsageServiceTest.java rename to usage-collection/src/test/java/com/sequenceiq/cloudbreak/usage/service/SecretRotationUsageSenderServiceTest.java index 169bd5f5e43..7f335d61a1d 100644 --- a/usage-collection/src/test/java/com/sequenceiq/cloudbreak/usage/service/SecretRotationUsageServiceTest.java +++ b/usage-collection/src/test/java/com/sequenceiq/cloudbreak/usage/service/SecretRotationUsageSenderServiceTest.java @@ -3,7 +3,6 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doNothing; -import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyNoInteractions; @@ -16,14 +15,12 @@ import com.cloudera.thunderhead.service.common.usage.UsageProto; import com.sequenceiq.cloudbreak.auth.ThreadBasedUserCrnProvider; -import com.sequenceiq.cloudbreak.rotation.secret.RotationFlowExecutionType; -import com.sequenceiq.cloudbreak.rotation.secret.SecretType; import com.sequenceiq.cloudbreak.usage.UsageReporter; @ExtendWith(MockitoExtension.class) -public class SecretRotationUsageServiceTest { +public class SecretRotationUsageSenderServiceTest { - private static final SecretType SECRET_TYPE = mock(SecretType.class); + private static final String SECRET_TYPE = "secretType"; private static final String RESOURCE_CRN = "resourceCrn"; @@ -35,90 +32,90 @@ public class SecretRotationUsageServiceTest { private UsageReporter usageReporter; @InjectMocks - private SecretRotationUsageService underTest; + private SecretRotationUsageSenderService underTest; @Test public void testRotationStartedWhenErrorOccurs() { - underTest.rotationStarted(null, null, null); + underTest.rotationStarted(null, null); verifyNoInteractions(usageReporter); } @Test public void testRotationFinishedWhenErrorOccurs() { - underTest.rotationFinished(null, null, null); + underTest.rotationFinished(null, null); verifyNoInteractions(usageReporter); } @Test public void testRotationFailedWhenErrorOccurs() { - underTest.rotationFailed(null, null, null, null); + underTest.rotationFailed(null, null, null); verifyNoInteractions(usageReporter); } @Test public void testRollbackStartedWhenErrorOccurs() { - underTest.rollbackStarted(null, null, null); + underTest.rollbackStarted(null, null); verifyNoInteractions(usageReporter); } @Test public void testRollbackFinishedWhenErrorOccurs() { - underTest.rollbackFinished(null, null, null); + underTest.rollbackFinished(null, null); verifyNoInteractions(usageReporter); } @Test public void testRollbackFailedWhenErrorOccurs() { - underTest.rollbackFailed(null, null, null, null); + underTest.rollbackFailed(null, null, null); verifyNoInteractions(usageReporter); } @Test public void testRotationStartedWhenExecutionTypeIsNotNull() { - underTest.rotationStarted(SECRET_TYPE, RESOURCE_CRN, RotationFlowExecutionType.ROTATE); + underTest.rotationStarted(SECRET_TYPE, RESOURCE_CRN); verifyNoInteractions(usageReporter); } @Test public void testRotationFinishedWhenExecutionTypeIsNotNull() { - underTest.rotationFinished(SECRET_TYPE, RESOURCE_CRN, RotationFlowExecutionType.ROTATE); + underTest.rotationFinished(SECRET_TYPE, RESOURCE_CRN); verifyNoInteractions(usageReporter); } @Test public void testRotationFailedWhenExecutionTypeIsNotNull() { - underTest.rotationFailed(SECRET_TYPE, RESOURCE_CRN, null, RotationFlowExecutionType.ROTATE); + underTest.rotationFailed(SECRET_TYPE, RESOURCE_CRN, null); verifyNoInteractions(usageReporter); } @Test public void testRollbackStartedWhenExecutionTypeIsNotNull() { - underTest.rollbackStarted(SECRET_TYPE, RESOURCE_CRN, RotationFlowExecutionType.ROTATE); + underTest.rollbackStarted(SECRET_TYPE, RESOURCE_CRN); verifyNoInteractions(usageReporter); } @Test public void testRollbackFinishedWhenExecutionTypeIsNotNull() { - underTest.rollbackFinished(SECRET_TYPE, RESOURCE_CRN, RotationFlowExecutionType.ROTATE); + underTest.rollbackFinished(SECRET_TYPE, RESOURCE_CRN); verifyNoInteractions(usageReporter); } @Test public void testRollbackFailedWhenExecutionTypeIsNotNull() { - underTest.rollbackFailed(SECRET_TYPE, RESOURCE_CRN, null, RotationFlowExecutionType.ROTATE); + underTest.rollbackFailed(SECRET_TYPE, RESOURCE_CRN, null); verifyNoInteractions(usageReporter); } @Test public void testRotationStarted() { doNothing().when(usageReporter).cdpSecretRotationEvent(any()); - ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.rotationStarted(SECRET_TYPE, RESOURCE_CRN, null)); + ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.rotationStarted(SECRET_TYPE, RESOURCE_CRN)); ArgumentCaptor eventCaptor = ArgumentCaptor.forClass(UsageProto.CDPSecretRotationEvent.class); verify(usageReporter).cdpSecretRotationEvent(eventCaptor.capture()); UsageProto.CDPSecretRotationEvent event = eventCaptor.getValue(); assertEquals(RESOURCE_CRN, event.getResourceCrn()); - assertEquals(SECRET_TYPE.toString(), event.getSecretType()); + assertEquals(SECRET_TYPE, event.getSecretType()); assertEquals("", event.getReason()); assertEquals(UsageProto.CDPSecretRotationStatus.Value.STARTED, event.getStatus()); } @@ -126,13 +123,13 @@ public void testRotationStarted() { @Test public void testRotationFinished() { doNothing().when(usageReporter).cdpSecretRotationEvent(any()); - ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.rotationFinished(SECRET_TYPE, RESOURCE_CRN, null)); + ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.rotationFinished(SECRET_TYPE, RESOURCE_CRN)); ArgumentCaptor eventCaptor = ArgumentCaptor.forClass(UsageProto.CDPSecretRotationEvent.class); verify(usageReporter).cdpSecretRotationEvent(eventCaptor.capture()); UsageProto.CDPSecretRotationEvent event = eventCaptor.getValue(); assertEquals(RESOURCE_CRN, event.getResourceCrn()); - assertEquals(SECRET_TYPE.toString(), event.getSecretType()); + assertEquals(SECRET_TYPE, event.getSecretType()); assertEquals("", event.getReason()); assertEquals(UsageProto.CDPSecretRotationStatus.Value.FINISHED, event.getStatus()); } @@ -140,13 +137,13 @@ public void testRotationFinished() { @Test public void testRotationFailed() { doNothing().when(usageReporter).cdpSecretRotationEvent(any()); - ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.rotationFailed(SECRET_TYPE, RESOURCE_CRN, REASON, null)); + ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.rotationFailed(SECRET_TYPE, RESOURCE_CRN, REASON)); ArgumentCaptor eventCaptor = ArgumentCaptor.forClass(UsageProto.CDPSecretRotationEvent.class); verify(usageReporter).cdpSecretRotationEvent(eventCaptor.capture()); UsageProto.CDPSecretRotationEvent event = eventCaptor.getValue(); assertEquals(RESOURCE_CRN, event.getResourceCrn()); - assertEquals(SECRET_TYPE.toString(), event.getSecretType()); + assertEquals(SECRET_TYPE, event.getSecretType()); assertEquals(REASON, event.getReason()); assertEquals(UsageProto.CDPSecretRotationStatus.Value.FAILED, event.getStatus()); } @@ -154,13 +151,13 @@ public void testRotationFailed() { @Test public void testRollbackStarted() { doNothing().when(usageReporter).cdpSecretRotationEvent(any()); - ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.rollbackStarted(SECRET_TYPE, RESOURCE_CRN, null)); + ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.rollbackStarted(SECRET_TYPE, RESOURCE_CRN)); ArgumentCaptor eventCaptor = ArgumentCaptor.forClass(UsageProto.CDPSecretRotationEvent.class); verify(usageReporter).cdpSecretRotationEvent(eventCaptor.capture()); UsageProto.CDPSecretRotationEvent event = eventCaptor.getValue(); assertEquals(RESOURCE_CRN, event.getResourceCrn()); - assertEquals(SECRET_TYPE.toString(), event.getSecretType()); + assertEquals(SECRET_TYPE, event.getSecretType()); assertEquals("", event.getReason()); assertEquals(UsageProto.CDPSecretRotationStatus.Value.ROLLBACK_STARTED, event.getStatus()); } @@ -168,13 +165,13 @@ public void testRollbackStarted() { @Test public void testRollbackFinished() { doNothing().when(usageReporter).cdpSecretRotationEvent(any()); - ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.rollbackFinished(SECRET_TYPE, RESOURCE_CRN, null)); + ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.rollbackFinished(SECRET_TYPE, RESOURCE_CRN)); ArgumentCaptor eventCaptor = ArgumentCaptor.forClass(UsageProto.CDPSecretRotationEvent.class); verify(usageReporter).cdpSecretRotationEvent(eventCaptor.capture()); UsageProto.CDPSecretRotationEvent event = eventCaptor.getValue(); assertEquals(RESOURCE_CRN, event.getResourceCrn()); - assertEquals(SECRET_TYPE.toString(), event.getSecretType()); + assertEquals(SECRET_TYPE, event.getSecretType()); assertEquals("", event.getReason()); assertEquals(UsageProto.CDPSecretRotationStatus.Value.ROLLBACK_FINISHED, event.getStatus()); } @@ -182,14 +179,14 @@ public void testRollbackFinished() { @Test public void testRollbackFailed() { doNothing().when(usageReporter).cdpSecretRotationEvent(any()); - ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.rollbackFailed(SECRET_TYPE, RESOURCE_CRN, REASON, null)); + ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.rollbackFailed(SECRET_TYPE, RESOURCE_CRN, REASON)); ArgumentCaptor eventCaptor = ArgumentCaptor.forClass(UsageProto.CDPSecretRotationEvent.class); verify(usageReporter).cdpSecretRotationEvent(eventCaptor.capture()); UsageProto.CDPSecretRotationEvent event = eventCaptor.getValue(); assertEquals(RESOURCE_CRN, event.getResourceCrn()); - assertEquals(SECRET_TYPE.toString(), event.getSecretType()); + assertEquals(SECRET_TYPE, event.getSecretType()); assertEquals(REASON, event.getReason()); assertEquals(UsageProto.CDPSecretRotationStatus.Value.ROLLBACK_FAILED, event.getStatus()); } -} +} \ No newline at end of file