use of io.cdap.cdap.api.plugin.InvalidPluginProperty in project cdap by caskdata.
the class PipelineSpecGenerator method getPlugin.
/**
* Adds a Plugin usage to the Application and create a new instance.
*
* @param stageName stage name
* @param etlPlugin plugin
* @param pluginSelector plugin selector
* @param type type of the plugin
* @param pluginName plugin name
* @param collector failure collector
* @throws ValidationException if error while creating new plugin instance
* @return new instance of the plugin
*/
private Object getPlugin(String stageName, ETLPlugin etlPlugin, TrackedPluginSelector pluginSelector, String type, String pluginName, FailureCollector collector) {
Object plugin = null;
Map<String, String> pluginProperties = etlPlugin.getProperties();
try {
// spec
if (runtimeEvaluator != null) {
pluginProperties = pluginConfigurer.evaluateMacros(etlPlugin.getProperties(), runtimeEvaluator, options);
}
// Call to usePlugin may throw IllegalArgumentException if the plugin with the same id is already deployed.
// This would mean there is a bug in the app and this can not be fixed by user. That is why it is not handled as
// a ValidationFailure.
plugin = pluginConfigurer.usePlugin(type, pluginName, stageName, PluginProperties.builder().addAll(pluginProperties).build(), pluginSelector);
} catch (InvalidPluginConfigException e) {
int numFailures = 0;
for (String missingProperty : e.getMissingProperties()) {
collector.addFailure(String.format("Required property '%s' has no value.", missingProperty), null).withConfigProperty(missingProperty);
numFailures++;
}
for (InvalidPluginProperty invalidProperty : e.getInvalidProperties()) {
collector.addFailure(e.getMessage(), null).withConfigProperty(invalidProperty.getName());
numFailures++;
}
// create a generic failure
if (numFailures == 0) {
collector.addFailure(e.getMessage(), null);
}
} catch (Exception e) {
// TODO: Catch specific exceptions when CDAP-15744 is fixed
collector.addFailure(e.getMessage(), null).withStacktrace(e.getStackTrace());
}
// throw validation exception if any error occurred while creating a new instance of the plugin
collector.getOrThrowException();
if (plugin == null) {
String errorMessage = String.format("Plugin named '%s' of type '%s' not found.", pluginName, type);
String correctiveAction = String.format("Make sure plugin '%s' of type '%s' is already deployed.", pluginName, type);
ArtifactSelectorConfig requested = etlPlugin.getArtifactConfig();
ArtifactId requestedArtifactId = requested == null ? null : new ArtifactId(requested.getName(), new ArtifactVersion(requested.getVersion()), ArtifactScope.valueOf(requested.getScope()));
ArtifactSelectorConfig suggestion = pluginSelector.getSuggestion();
ArtifactId suggestedArtifactId = null;
if (suggestion != null) {
suggestedArtifactId = new ArtifactId(suggestion.getName(), new ArtifactVersion(suggestion.getVersion()), ArtifactScope.valueOf(suggestion.getScope()));
}
collector.addFailure(errorMessage, correctiveAction).withPluginNotFound(stageName, pluginName, type, requestedArtifactId, suggestedArtifactId);
// throw validation exception if the plugin is not initialized
collector.getOrThrowException();
}
return plugin;
}
Aggregations