Search in sources :

Example 1 with ApplicationUpdateContext

use of io.cdap.cdap.api.app.ApplicationUpdateContext in project cdap by caskdata.

the class ETLStage method upgradePlugin.

/**
 * Upgrade plugin used in the stage.
 * 1. If plugin is using fixed version and a new plugin artifact is found with higher version in SYSTEM scope,
 *    use the new plugin.
 * 2. If plugin is using a plugin range and a new plugin artifact is found with higher version in SYSTEM scope,
 *    move the upper bound of the range to include the new plugin artifact. Also change plugin scope.
 *    If new plugin is in range, do not change range. (Note: It would not change range even though new plugin is in
 *    different scope).
 *
 * @param updateContext To use helper functions like getPluginArtifacts.
 * @return Updated plugin object to be used for the udated stage. Returned null if no changes to current plugin.
 */
private ETLPlugin upgradePlugin(ApplicationUpdateContext updateContext) throws Exception {
    // Find the plugin with max version from available candidates.
    Optional<ArtifactId> newPluginCandidate = updateContext.getPluginArtifacts(plugin.getType(), plugin.getName(), null).stream().max(Comparator.comparing(artifactId -> artifactId.getVersion()));
    if (!newPluginCandidate.isPresent()) {
        // TODO: Consider throwing exception here.
        return plugin;
    }
    ArtifactId newPlugin = newPluginCandidate.get();
    String newVersion = getUpgradedVersionString(newPlugin);
    // If getUpgradedVersionString returns null, candidate plugin is not valid for upgrade.
    if (newVersion == null) {
        return plugin;
    }
    ArtifactSelectorConfig newArtifactSelectorConfig = new ArtifactSelectorConfig(newPlugin.getScope().name(), newPlugin.getName(), newVersion);
    io.cdap.cdap.etl.proto.v2.ETLPlugin upgradedEtlPlugin = new io.cdap.cdap.etl.proto.v2.ETLPlugin(plugin.getName(), plugin.getType(), plugin.getProperties(), newArtifactSelectorConfig, plugin.getLabel());
    return upgradedEtlPlugin;
}
Also used : Objects(java.util.Objects) ArtifactVersionRange(io.cdap.cdap.api.artifact.ArtifactVersionRange) Logger(org.slf4j.Logger) ArtifactSelectorConfig(io.cdap.cdap.etl.proto.ArtifactSelectorConfig) ApplicationConfigUpdateAction(io.cdap.cdap.api.app.ApplicationConfigUpdateAction) ApplicationUpdateContext(io.cdap.cdap.api.app.ApplicationUpdateContext) UpgradeContext(io.cdap.cdap.etl.proto.UpgradeContext) LoggerFactory(org.slf4j.LoggerFactory) Optional(java.util.Optional) Comparator(java.util.Comparator) ArtifactId(io.cdap.cdap.api.artifact.ArtifactId) Nullable(javax.annotation.Nullable) ArtifactId(io.cdap.cdap.api.artifact.ArtifactId) ArtifactSelectorConfig(io.cdap.cdap.etl.proto.ArtifactSelectorConfig)

Aggregations

ApplicationConfigUpdateAction (io.cdap.cdap.api.app.ApplicationConfigUpdateAction)1 ApplicationUpdateContext (io.cdap.cdap.api.app.ApplicationUpdateContext)1 ArtifactId (io.cdap.cdap.api.artifact.ArtifactId)1 ArtifactVersionRange (io.cdap.cdap.api.artifact.ArtifactVersionRange)1 ArtifactSelectorConfig (io.cdap.cdap.etl.proto.ArtifactSelectorConfig)1 UpgradeContext (io.cdap.cdap.etl.proto.UpgradeContext)1 Comparator (java.util.Comparator)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 Nullable (javax.annotation.Nullable)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1