Skip to content

Commit

Permalink
refactor(core): remove deprecated ProviderVersion methods (#4734)
Browse files Browse the repository at this point in the history
After [deprecating](#4721) ProviderVersion and associated methods for one release (v5.64.0), we can now safely remove this functionality. Halyard defines its own [ProviderVersion enum](https://github.com/spinnaker/halyard/blob/master/halyard-config/src/main/java/com/netflix/spinnaker/halyard/config/model/v1/providers/kubernetes/KubernetesAccount.java#L197) which will live indefinitely for users deploying to older versions of Spinnaker.

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
maggieneterval and mergify[bot] committed Jul 9, 2020
1 parent 0cb1a9a commit 11294d1
Show file tree
Hide file tree
Showing 10 changed files with 12 additions and 372 deletions.
Expand Up @@ -17,25 +17,11 @@

package com.netflix.spinnaker.clouddriver.orchestration;

import com.netflix.spinnaker.clouddriver.security.ProviderVersion;
import com.netflix.spinnaker.kork.annotations.Beta;
import javax.annotation.Nullable;

@Beta
public interface VersionedCloudProviderOperation {
/**
* Various operations can satisfy different provider's versions. This operation will only be
* applicable to accounts at this version.
*
* @return true i.f.f. this operations works on accounts at this version
* @deprecated {@link com.netflix.spinnaker.clouddriver.security.ProviderVersion} is deprecated.
* This method will be removed in a future release.
*/
@Deprecated
default boolean acceptsVersion(ProviderVersion version) {
return ProviderVersion.v1.equals(version);
}

/**
* Allows individual operations to be versioned.
*
Expand Down
Expand Up @@ -65,20 +65,6 @@ public interface AccountCredentials<T> {
*/
String getAccountType();

/**
* Provides the "version" of the account's provider. If an account has been configured at a
* particular version, it can be supported by different caching agents and operation converters.
* By default every account is at version v1.
*
* @return the account's version.
* @deprecated {@link com.netflix.spinnaker.clouddriver.security.ProviderVersion} is deprecated.
* This method will be removed in a future release.
*/
@Deprecated
default ProviderVersion getProviderVersion() {
return ProviderVersion.v1;
}

/** @return the id for the account (may be null if not supported by underlying cloud provider) */
default String getAccountId() {
return null;
Expand Down

This file was deleted.

Expand Up @@ -20,7 +20,6 @@ import com.google.common.base.Splitter
import com.netflix.spinnaker.clouddriver.core.CloudProvider
import com.netflix.spinnaker.clouddriver.deploy.DescriptionValidator
import com.netflix.spinnaker.clouddriver.exceptions.CloudProviderNotFoundException
import com.netflix.spinnaker.clouddriver.security.ProviderVersion
import com.netflix.spinnaker.kork.exceptions.UserException
import groovy.util.logging.Slf4j
import org.springframework.beans.factory.NoSuchBeanDefinitionException
Expand Down Expand Up @@ -106,91 +105,6 @@ class AnnotationsBasedAtomicOperationsRegistry extends ApplicationContextAtomicO
return validators ? (DescriptionValidator) validators[0] : null
}

/**
* @deprecated {@link com.netflix.spinnaker.clouddriver.security.ProviderVersion}
* is deprecated. This method will be removed in a future release. Use
* {@link #getAtomicOperationConverter(String, String)} instead.
*/
@Override
@Deprecated
AtomicOperationConverter getAtomicOperationConverter(String description, String cloudProvider, ProviderVersion version) {
// Legacy naming convention which is not generic and description name is specific to cloud provider
try {
AtomicOperationConverter converter = super.getAtomicOperationConverter(description, cloudProvider, version)
if (converter) return converter
} catch (NoSuchBeanDefinitionException e) {
/**
* If 'cloudProvider' is not specified then it means that caller was querying the bean as per the old cloud provider
* specific name and if no bean found then we can't do anything here other than throwing the NoSuchBeanDefinitionException
*
* TO-DO: Once all the operations have been migrated as per the new naming scheme that is not cloud provider specific, then
* make the 'description' and 'cloudProvider' arguments mandatory for this method
*/
if (!cloudProvider) {
throw e
}
}

// Operations can be versioned (within the same provider version)
VersionedDescription versionedDescription = VersionedDescription.from(description)

Class<? extends Annotation> providerAnnotationType = getCloudProviderAnnotation(cloudProvider)

List converters = applicationContext.getBeansWithAnnotation(providerAnnotationType).findAll { key, value ->
VersionedDescription converterVersion = VersionedDescription.from(value.getClass().getAnnotation(providerAnnotationType).value())
converterVersion.descriptionName == versionedDescription.descriptionName && value instanceof AtomicOperationConverter
}.values().toList()

converters = VersionedOperationHelper.findVersionMatches(version, converters)
converters = VersionedOperationHelper.findVersionMatches(versionedDescription.version, converters)

if (!converters) {
throw new AtomicOperationConverterNotFoundException(
"No atomic operation converter found for description '${description}' and cloud provider '${cloudProvider}'. " +
"It is possible that either 1) the account name used for the operation is incorrect, or 2) the account name used for the operation is unhealthy/unable to communicate with ${cloudProvider}."
)
}

if (converters.size() > 1) {
throw new RuntimeException(
"More than one (${converters.size()}) atomic operation converters found for description '${description}' and cloud provider " +
"'${cloudProvider}' at version '${version}'"
)
}

return (AtomicOperationConverter) converters[0]
}

/**
* @deprecated {@link com.netflix.spinnaker.clouddriver.security.ProviderVersion}
* is deprecated. This method will be removed in a future release. Use
* {@link #getAtomicOperationDescriptionValidator(String, String)} instead.
*/
@Override
@Deprecated
DescriptionValidator getAtomicOperationDescriptionValidator(String validator, String cloudProvider, ProviderVersion version) {
// Legacy naming convention which is not generic and validator name is specific to cloud provider
try {
DescriptionValidator descriptionValidator = super.getAtomicOperationDescriptionValidator(validator, cloudProvider, version)
if (descriptionValidator) {
return descriptionValidator
}
} catch (NoSuchBeanDefinitionException e) {}

if (!cloudProvider) return null

Class<? extends Annotation> providerAnnotationType = getCloudProviderAnnotation(cloudProvider)

List validators = applicationContext.getBeansWithAnnotation(providerAnnotationType).findAll { key, value ->
DescriptionValidator.getValidatorName(value.getClass().getAnnotation(providerAnnotationType).value()) == validator &&
value instanceof DescriptionValidator
}.values().toList()

validators = VersionedOperationHelper.findVersionMatches(version, validators)

return validators ? (DescriptionValidator) validators[0] : null
}

protected Class<? extends Annotation> getCloudProviderAnnotation(String cloudProvider) {
List<CloudProvider> cloudProviderInstances = cloudProviders.findAll { it.id == cloudProvider }
if (!cloudProviderInstances) {
Expand Down
Expand Up @@ -17,7 +17,6 @@
package com.netflix.spinnaker.clouddriver.orchestration

import com.netflix.spinnaker.clouddriver.deploy.DescriptionValidator
import com.netflix.spinnaker.clouddriver.security.ProviderVersion
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.context.ApplicationContext

Expand All @@ -40,36 +39,4 @@ class ApplicationContextAtomicOperationsRegistry implements AtomicOperationsRegi
DescriptionValidator getAtomicOperationDescriptionValidator(String validator, String cloudProvider) {
return (DescriptionValidator) applicationContext.getBean(validator)
}

/**
* @deprecated {@link com.netflix.spinnaker.clouddriver.security.ProviderVersion}
* is deprecated. This method will be removed in a future release. Use
* {@link #getAtomicOperationConverter(String, String)} instead.
*/
@Override
@Deprecated
AtomicOperationConverter getAtomicOperationConverter(String description, String cloudProvider, ProviderVersion version) {
def result = (AtomicOperationConverter) applicationContext.getBean(description)
if (!result.acceptsVersion(version)) {
throw new AtomicOperationConverterNotFoundException("Converter version mismatch. Converter '$description' not applicable for '$version'")
}

return result
}

/**
* @deprecated {@link com.netflix.spinnaker.clouddriver.security.ProviderVersion}
* is deprecated. This method will be removed in a future release. Use
* {@link #getAtomicOperationDescriptionValidator(String, String)} instead.
*/
@Override
@Deprecated
DescriptionValidator getAtomicOperationDescriptionValidator(String validator, String cloudProvider, ProviderVersion version) {
def result = (DescriptionValidator) applicationContext.getBean(validator)
if (!result.acceptsVersion(version)) {
throw new AtomicOperationConverterNotFoundException("Validator version mismatch. Validator '$validator' not applicable for '$version'")
}

return result
}
}
Expand Up @@ -17,7 +17,6 @@
package com.netflix.spinnaker.clouddriver.orchestration

import com.netflix.spinnaker.clouddriver.deploy.DescriptionValidator
import com.netflix.spinnaker.clouddriver.security.ProviderVersion

import javax.annotation.Nullable

Expand All @@ -43,32 +42,4 @@ interface AtomicOperationsRegistry {
* @return
*/
@Nullable DescriptionValidator getAtomicOperationDescriptionValidator(String validator, String cloudProvider)

/**
*
* @param description
* @param cloudProvider
* @param providerVersion
* @return
*
* @deprecated {@link com.netflix.spinnaker.clouddriver.security.ProviderVersion}
* is deprecated. This method will be removed in a future release. Use
* {@link #getAtomicOperationConverter(String, String)} instead.
*/
@Deprecated
AtomicOperationConverter getAtomicOperationConverter(String description, String cloudProvider, ProviderVersion version)

/**
*
* @param validator
* @param cloudProvider
* @param providerVersion
* @return
*
* @deprecated {@link com.netflix.spinnaker.clouddriver.security.ProviderVersion}
* is deprecated. This method will be removed in a future release. Use
* {@link #getAtomicOperationDescriptionValidator(String, String)} instead.
*/
@Deprecated
@Nullable DescriptionValidator getAtomicOperationDescriptionValidator(String validator, String cloudProvider, ProviderVersion version)
}
Expand Up @@ -17,24 +17,13 @@

package com.netflix.spinnaker.clouddriver.orchestration;

import com.netflix.spinnaker.clouddriver.security.ProviderVersion;
import com.netflix.spinnaker.kork.annotations.NonnullByDefault;
import java.util.List;
import java.util.stream.Collectors;
import javax.annotation.Nullable;

@NonnullByDefault
public class VersionedOperationHelper {
/**
* @deprecated {@link com.netflix.spinnaker.clouddriver.security.ProviderVersion} is deprecated.
* This method will be removed in a future release.
*/
@Deprecated
static <T extends VersionedCloudProviderOperation> List<T> findVersionMatches(
ProviderVersion version, List<T> converters) {
return converters.stream().filter(o -> o.acceptsVersion(version)).collect(Collectors.toList());
}

static <T extends VersionedCloudProviderOperation> List<T> findVersionMatches(
@Nullable String version, List<T> converters) {
return converters.stream()
Expand Down

0 comments on commit 11294d1

Please sign in to comment.