|
|
@ -21,10 +21,17 @@ import static java.util.Objects.requireNonNull; |
|
|
|
|
|
|
|
|
|
|
|
import org.apache.dolphinscheduler.dao.entity.PluginDefine; |
|
|
|
import org.apache.dolphinscheduler.dao.entity.PluginDefine; |
|
|
|
import org.apache.dolphinscheduler.dao.mapper.PluginDefineMapper; |
|
|
|
import org.apache.dolphinscheduler.dao.mapper.PluginDefineMapper; |
|
|
|
|
|
|
|
import org.apache.dolphinscheduler.plugin.task.api.TaskPluginException; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.Objects; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import lombok.NonNull; |
|
|
|
|
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
|
|
|
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.stereotype.Component; |
|
|
|
import org.springframework.stereotype.Component; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Slf4j |
|
|
|
@Component |
|
|
|
@Component |
|
|
|
public class PluginDao { |
|
|
|
public class PluginDao { |
|
|
|
|
|
|
|
|
|
|
@ -44,21 +51,36 @@ public class PluginDao { |
|
|
|
* add or update plugin define |
|
|
|
* add or update plugin define |
|
|
|
* |
|
|
|
* |
|
|
|
* @param pluginDefine new pluginDefine |
|
|
|
* @param pluginDefine new pluginDefine |
|
|
|
|
|
|
|
* @return plugin id |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public int addOrUpdatePluginDefine(PluginDefine pluginDefine) { |
|
|
|
public int addOrUpdatePluginDefine(@NonNull PluginDefine pluginDefine) { |
|
|
|
requireNonNull(pluginDefine, "pluginDefine is null"); |
|
|
|
|
|
|
|
requireNonNull(pluginDefine.getPluginName(), "pluginName is null"); |
|
|
|
requireNonNull(pluginDefine.getPluginName(), "pluginName is null"); |
|
|
|
requireNonNull(pluginDefine.getPluginType(), "pluginType is null"); |
|
|
|
requireNonNull(pluginDefine.getPluginType(), "pluginType is null"); |
|
|
|
|
|
|
|
|
|
|
|
PluginDefine currPluginDefine = |
|
|
|
PluginDefine currPluginDefine = |
|
|
|
pluginDefineMapper.queryByNameAndType(pluginDefine.getPluginName(), pluginDefine.getPluginType()); |
|
|
|
pluginDefineMapper.queryByNameAndType(pluginDefine.getPluginName(), pluginDefine.getPluginType()); |
|
|
|
if (currPluginDefine == null) { |
|
|
|
if (currPluginDefine == null) { |
|
|
|
if (pluginDefineMapper.insert(pluginDefine) == 1 && pluginDefine.getId() != null) { |
|
|
|
try { |
|
|
|
return pluginDefine.getId(); |
|
|
|
if (pluginDefineMapper.insert(pluginDefine) == 1 && pluginDefine.getId() != null) { |
|
|
|
|
|
|
|
return pluginDefine.getId(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
throw new TaskPluginException( |
|
|
|
|
|
|
|
String.format("Failed to insert plugin definition, pluginName: %s, pluginType: %s", |
|
|
|
|
|
|
|
pluginDefine.getPluginName(), pluginDefine.getPluginType())); |
|
|
|
|
|
|
|
} catch (TaskPluginException ex) { |
|
|
|
|
|
|
|
throw ex; |
|
|
|
|
|
|
|
} catch (Exception ex) { |
|
|
|
|
|
|
|
log.error("Insert plugin definition error, there may already exist a plugin", ex); |
|
|
|
|
|
|
|
currPluginDefine = pluginDefineMapper.queryByNameAndType(pluginDefine.getPluginName(), |
|
|
|
|
|
|
|
pluginDefine.getPluginType()); |
|
|
|
|
|
|
|
if (currPluginDefine == null) { |
|
|
|
|
|
|
|
throw new TaskPluginException( |
|
|
|
|
|
|
|
String.format("Failed to insert plugin definition, pluginName: %s, pluginType: %s", |
|
|
|
|
|
|
|
pluginDefine.getPluginName(), pluginDefine.getPluginType())); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
throw new IllegalStateException("Failed to insert plugin definition"); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
if (!currPluginDefine.getPluginParams().equals(pluginDefine.getPluginParams())) { |
|
|
|
if (!Objects.equals(currPluginDefine.getPluginParams(), pluginDefine.getPluginParams())) { |
|
|
|
currPluginDefine.setUpdateTime(pluginDefine.getUpdateTime()); |
|
|
|
currPluginDefine.setUpdateTime(pluginDefine.getUpdateTime()); |
|
|
|
currPluginDefine.setPluginParams(pluginDefine.getPluginParams()); |
|
|
|
currPluginDefine.setPluginParams(pluginDefine.getPluginParams()); |
|
|
|
pluginDefineMapper.updateById(currPluginDefine); |
|
|
|
pluginDefineMapper.updateById(currPluginDefine); |
|
|
|