Skip to content

Commit

Permalink
use ADVHelper in DelinquentWorkspaceCronJob (#7499)
Browse files Browse the repository at this point in the history
  • Loading branch information
pedroslopez committed Jun 27, 2023
1 parent b188387 commit 5bbe770
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import io.airbyte.config.ActorDefinitionVersion;
import io.airbyte.config.ActorType;
import io.airbyte.config.ReleaseStage;
import io.airbyte.config.StandardDestinationDefinition;
import io.airbyte.config.StandardSourceDefinition;
import io.airbyte.config.persistence.version_overrides.DefinitionVersionOverrideProvider;
Expand All @@ -14,6 +15,7 @@
import io.airbyte.featureflag.Workspace;
import jakarta.inject.Singleton;
import java.io.IOException;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
import javax.annotation.Nullable;
Expand Down Expand Up @@ -142,8 +144,49 @@ public ActorDefinitionVersion getDestinationVersion(final StandardDestinationDef
return getDestinationVersion(destinationDefinition, workspaceId, null);
}

/**
* Helper method to share eligibility logic for free connector program. Checks if either the source
* or destination is in alpha or beta status.
*
* @param workspaceId workspace id
* @param sourceDefinition source definition
* @param sourceId source id
* @param destinationDefinition destination definition
* @param destinationId destination id
* @return true if either the source or destination is alpha or beta
*/
public boolean getSourceOrDestinationIsAlphaOrBeta(final UUID workspaceId,
final StandardSourceDefinition sourceDefinition,
final UUID sourceId,
final StandardDestinationDefinition destinationDefinition,
final UUID destinationId)
throws ConfigNotFoundException, IOException {
final ActorDefinitionVersion sourceVersion = getSourceVersion(sourceDefinition, workspaceId, sourceId);
final ActorDefinitionVersion destinationVersion = getDestinationVersion(destinationDefinition, workspaceId, destinationId);

return hasAlphaOrBetaVersion(List.of(sourceVersion, destinationVersion));
}

/**
* Get the docker image name (docker_repository:docker_image_tag) for a given actor definition
* version.
*
* @param actorDefinitionVersion actor definition version
* @return docker image name
*/
public static String getDockerImageName(final ActorDefinitionVersion actorDefinitionVersion) {
return String.format("%s:%s", actorDefinitionVersion.getDockerRepository(), actorDefinitionVersion.getDockerImageTag());
}

/**
* Helper method to share eligibility logic for free connector program.
*
* @param actorDefinitionVersions List of versions that should be checked for alpha/beta status
* @return true if any of the provided versions is in alpha or beta
*/
public static boolean hasAlphaOrBetaVersion(final List<ActorDefinitionVersion> actorDefinitionVersions) {
return actorDefinitionVersions.stream()
.anyMatch(version -> version.getReleaseStage().equals(ReleaseStage.ALPHA) || version.getReleaseStage().equals(ReleaseStage.BETA));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2505,6 +2505,10 @@ public Geography getGeographyForWorkspace(final UUID workspaceId) throws IOExcep
* sign up for the program. This check is performed on nearly every page load so the query needs to
* be as efficient as possible.
*
* This should only be used for efficiently determining eligibility for the Free Connector Program.
* Anything that involves billing should instead use the ActorDefinitionVersionHelper to determine
* the ReleaseStages.
*
* @param workspaceId ID of the workspace to check connectors for
* @return boolean indicating if an alpha or beta connector exists within the workspace
*/
Expand All @@ -2529,6 +2533,10 @@ public boolean getWorkspaceHasAlphaOrBetaConnector(final UUID workspaceId) throw
* as the workspace is enrolled in the Free Connector Program. This check is used to allow free
* connections to continue running even when a workspace runs out of credits.
*
* This should only be used for efficiently determining eligibility for the Free Connector Program.
* Anything that involves billing should instead use the ActorDefinitionVersionHelper to determine
* the ReleaseStages.
*
* @param connectionId ID of the connection to check connectors for
* @return boolean indicating if an alpha or beta connector is used by the connection
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import io.airbyte.commons.json.Jsons;
import io.airbyte.config.ActorDefinitionVersion;
import io.airbyte.config.ActorType;
import io.airbyte.config.ReleaseStage;
import io.airbyte.config.StandardDestinationDefinition;
import io.airbyte.config.StandardSourceDefinition;
import io.airbyte.config.persistence.version_overrides.DefinitionVersionOverrideProvider;
Expand All @@ -23,11 +24,14 @@
import io.airbyte.featureflag.Workspace;
import io.airbyte.protocol.models.ConnectorSpecification;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.UUID;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;

class ActorDefinitionVersionHelperTest {

Expand Down Expand Up @@ -231,4 +235,12 @@ void testGetDefaultDestinationVersionWithNoDefaultThrows() {
assertTrue(exception.getMessage().contains("has no default version"));
}

@ParameterizedTest
@CsvSource({"alpha,generally_available,true", "beta,generally_available,true", "generally_available,generally_available,false", "alpha,beta,true"})
void testHasAlphaOrBeta(final String sourceReleaseStageStr, final String destinationReleaseStageStr, final boolean expected) {
final ActorDefinitionVersion sourceDefVersion = new ActorDefinitionVersion().withReleaseStage(ReleaseStage.fromValue(sourceReleaseStageStr));
final ActorDefinitionVersion destDefVersion = new ActorDefinitionVersion().withReleaseStage(ReleaseStage.fromValue(destinationReleaseStageStr));
assertEquals(expected, ActorDefinitionVersionHelper.hasAlphaOrBetaVersion(List.of(sourceDefVersion, destDefVersion)));
}

}

0 comments on commit 5bbe770

Please sign in to comment.