All Downloads are FREE. Search and download functionalities are using the official Maven repository.
Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
io.cdap.cdap.internal.app.customaction.DefaultCustomActionConfigurer Maven / Gradle / Ivy
/*
* Copyright © 2016-2018 Cask Data, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package io.cdap.cdap.internal.app.customaction;
import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
import io.cdap.cdap.api.customaction.CustomAction;
import io.cdap.cdap.api.customaction.CustomActionConfigurer;
import io.cdap.cdap.api.customaction.CustomActionSpecification;
import io.cdap.cdap.api.feature.FeatureFlagsProvider;
import io.cdap.cdap.common.id.Id;
import io.cdap.cdap.internal.app.AbstractConfigurer;
import io.cdap.cdap.internal.app.deploy.pipeline.AppDeploymentRuntimeInfo;
import io.cdap.cdap.internal.app.runtime.artifact.PluginFinder;
import io.cdap.cdap.internal.app.runtime.plugin.PluginInstantiator;
import io.cdap.cdap.internal.customaction.DefaultCustomActionSpecification;
import io.cdap.cdap.internal.lang.Reflections;
import io.cdap.cdap.internal.specification.DataSetFieldExtractor;
import io.cdap.cdap.internal.specification.PropertyFieldExtractor;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import javax.annotation.Nullable;
/**
* Default implementation of the {@link CustomActionConfigurer}.
*/
public final class DefaultCustomActionConfigurer extends AbstractConfigurer implements CustomActionConfigurer {
private final CustomAction customAction;
private String name;
private String description;
private Map properties;
private DefaultCustomActionConfigurer(CustomAction customAction, Id.Namespace deployNamespace, Id.Artifact artifactId,
PluginFinder pluginFinder, PluginInstantiator pluginInstantiator,
@Nullable AppDeploymentRuntimeInfo runtimeInfo,
FeatureFlagsProvider featureFlagsProvider) {
super(deployNamespace, artifactId, pluginFinder , pluginInstantiator, runtimeInfo, featureFlagsProvider);
this.customAction = customAction;
this.name = customAction.getClass().getSimpleName();
this.description = "";
this.properties = new HashMap<>();
}
@Override
public void setName(String name) {
Preconditions.checkArgument(!Strings.isNullOrEmpty(name), "Name of the CustomAction cannot be null or empty");
this.name = name;
}
@Override
public void setDescription(String description) {
Preconditions.checkNotNull(description, "Description of the CustomAction cannot be null");
this.description = description;
}
@Override
public void setProperties(Map properties) {
Preconditions.checkNotNull(properties, "Properties of the CustomAction cannot be null");
this.properties = new HashMap<>(properties);
}
private DefaultCustomActionSpecification createSpecification() {
Set datasets = new HashSet<>();
Reflections.visit(customAction, customAction.getClass(), new PropertyFieldExtractor(properties),
new DataSetFieldExtractor(datasets));
return new DefaultCustomActionSpecification(customAction.getClass().getName(), name,
description, properties, datasets);
}
public static CustomActionSpecification configureAction(CustomAction action, Id.Namespace deployNamespace,
Id.Artifact artifactId, PluginFinder pluginFinder,
PluginInstantiator pluginInstantiator,
@Nullable AppDeploymentRuntimeInfo runtimeInfo,
FeatureFlagsProvider featureFlagsProvider) {
DefaultCustomActionConfigurer configurer = new DefaultCustomActionConfigurer(action, deployNamespace, artifactId,
pluginFinder,
pluginInstantiator,
runtimeInfo,
featureFlagsProvider);
action.configure(configurer);
return configurer.createSpecification();
}
}