use of com.qlangtech.tis.TIS in project plugins by qlangtech.
the class TestPlugin method testReceiceRequestFromClient.
public void testReceiceRequestFromClient() throws Exception {
com.alibaba.fastjson.JSONArray jsonArray = null;
com.alibaba.fastjson.JSONObject jsonObject = null;
com.alibaba.fastjson.JSONObject valJ = null;
String impl = null;
PropertyType attrDesc = null;
Descriptor descriptor = null;
JSONArray vals = null;
String attr = null;
String attrVal = null;
TIS tis = TIS.get();
// IncrComponent incrComponent = tis.loadIncrComponent(collection);
// incrComponent.setMqListenerFactory();
Describable describable = null;
try (InputStream input = TestPlugin.class.getResourceAsStream("RocketMQListenerFactory.json")) {
assertNotNull(input);
jsonArray = JSONArray.parseArray(IOUtils.toString(input, TisUTF8.getName()));
for (int i = 0; i < jsonArray.size(); i++) {
// 创建一个item
jsonObject = jsonArray.getJSONObject(i);
describable = (Describable) parseDescribable(jsonObject).instance;
}
}
assertNotNull(describable);
RocketMQListenerFactory mqListenerFactory = (RocketMQListenerFactory) describable;
assertEquals(MQ_TOPIC, mqListenerFactory.getMqTopic());
assertEquals(NamesrvAddr, mqListenerFactory.getNamesrvAddr());
assertEquals(consumeId, mqListenerFactory.consumeName);
assertNotNull(mqListenerFactory.getDeserialize());
}
use of com.qlangtech.tis.TIS in project tis by qlangtech.
the class PluginAction method doGetExtensionPointShow.
public void doGetExtensionPointShow(Context context) throws Exception {
TIS tis = TIS.get();
this.setBizResult(context, tis.loadGlobalComponent().isShowExtensionDetail());
}
use of com.qlangtech.tis.TIS in project tis by qlangtech.
the class PluginAction method doSwitchExtensionPointShow.
/**
* @param context
* @throws Exception
*/
public void doSwitchExtensionPointShow(Context context) throws Exception {
boolean open = this.getBoolean("switch");
TIS tis = TIS.get();
tis.saveComponent(tis.loadGlobalComponent().setShowExtensionDetail(open));
}
use of com.qlangtech.tis.TIS in project tis by qlangtech.
the class GenerateDAOAndIncrScript method generateDAOScript.
// private void compileAndPackage(Context context, IControlMsgHandler msgHandler, Map<DBNode, List<String>> dbNameMap, File sourceRoot) throws Exception {
// /**
// * *********************************************************************************
// * 编译增量脚本
// * ***********************************************************************************
// */
// if (this.streamScriptCompile(sourceRoot, dbNameMap.keySet())) {
// msgHandler.addErrorMessage(context, "增量脚本编译失败");
// msgHandler.addFieldError(context, "incr_script_compile_error", "error");
// return;
// }
// /**
// * *********************************************************************************
// * 对scala代码进行 打包
// * ***********************************************************************************
// */
// JavaCompilerProcess.SourceGetterStrategy getterStrategy
// = new JavaCompilerProcess.SourceGetterStrategy(false, "/src/main/scala", ".scala") {
//
// @Override
// public JavaFileObject.Kind getSourceKind() {
// // 没有scala的类型,暂且用other替换一下
// return JavaFileObject.Kind.OTHER;
// }
//
// @Override
// public MyJavaFileObject processMyJavaFileObject(MyJavaFileObject fileObj) {
// try {
// try (InputStream input = FileUtils.openInputStream(fileObj.getSourceFile())) {
// IOUtils.copy(input, fileObj.openOutputStream());
// }
// } catch (IOException e) {
// throw new RuntimeException(e);
// }
// return fileObj;
// }
// };
// //
// JavaCompilerProcess.FileObjectsContext fileObjects = JavaCompilerProcess.getFileObjects(sourceRoot, getterStrategy);
// final JavaCompilerProcess.FileObjectsContext compiledCodeContext = new JavaCompilerProcess.FileObjectsContext();
// File streamScriptClassesDir = new File(sourceRoot, "classes");
// appendClassFile(streamScriptClassesDir, compiledCodeContext, null);
// // 取得spring配置文件相关resourece
// JavaCompilerProcess.FileObjectsContext xmlConfigs = indexStreamCodeGenerator.getSpringXmlConfigsObjectsContext();
//
// JavaCompilerProcess.packageJar(
// sourceRoot, StreamContextConstant.getIncrStreamJarName(indexStreamCodeGenerator.collection)
// , fileObjects, compiledCodeContext, xmlConfigs);
// }
private void generateDAOScript(Context context, Map<Integer, Long> dependencyDbs) throws Exception {
final Map<DBNode, List<String>> dbNameMap = Collections.unmodifiableMap(indexStreamCodeGenerator.getDbTables());
if (dbNameMap.size() < 1) {
throw new IllegalStateException("dbNameMap size can not small than 1");
}
if (dbNameMap.size() != dependencyDbs.size()) {
throw new IllegalStateException("dbNameMap.size() " + dbNameMap.size() + " != dependencyDbs.size()" + dependencyDbs.size());
}
// long timestampp;// = Long.parseLong(ManageUtils.formatNowYyyyMMddHHmmss());
DataSourceFactoryPluginStore dbPluginStore = null;
final KoubeiProgressCallback koubeiProgressCallback = new KoubeiProgressCallback();
List<IbatorContext> daoFacadeList = Lists.newArrayList();
Long lastOptime = null;
List<DataSourceFactoryPluginStore> leakFacadeDsPlugin = Lists.newArrayList();
for (Map.Entry<DBNode, List<String>> /* dbname */
entry : dbNameMap.entrySet()) {
dbPluginStore = getFacadePluginStore(entry);
if (dbPluginStore.getPlugin() == null) {
leakFacadeDsPlugin.add(dbPluginStore);
}
}
if (leakFacadeDsPlugin.size() > 0) {
this.msgHandler.addErrorMessage(context, "数据库:" + leakFacadeDsPlugin.stream().map((p) -> "'" + p.getDSKey().keyVal + "'").collect(Collectors.joining(",")) + "还没有定义对应的Facade数据源");
return;
}
for (Map.Entry<DBNode, List<String>> /* dbname */
entry : dbNameMap.entrySet()) {
lastOptime = dependencyDbs.get(entry.getKey().getDbId());
if (lastOptime == null) {
throw new IllegalStateException("db " + entry.getKey() + " is not find in dependency dbs:" + dbNameMap.keySet().stream().map((r) -> "[" + r.getDbId() + ":" + r.getDbName() + "]").collect(Collectors.joining(",")));
}
long timestamp = lastOptime;
dbPluginStore = getFacadePluginStore(entry);
FacadeDataSource facadeDataSource = dbPluginStore.createFacadeDataSource();
IbatorProperties properties = new IbatorProperties(facadeDataSource, entry.getValue(), timestamp);
entry.getKey().setTimestampVer(timestamp);
if (entry.getValue().size() < 1) {
throw new IllegalStateException("db:" + entry.getKey() + " relevant tablesList can not small than 1");
}
KoubeiIbatorRunner runner = new KoubeiIbatorRunner(properties) {
@Override
protected KoubeiProgressCallback getProgressCallback() {
return koubeiProgressCallback;
}
};
IbatorContext ibatorContext = runner.getIbatorContext();
daoFacadeList.add(ibatorContext);
try {
if (!properties.isDaoScriptCreated()) {
// 生成源代码
runner.build();
// dao script 脚本已经创建不需要再创建了
// if (compilerAndPackage) {
// 直接生成就行了,别管当前是不是要编译了
File classpathDir = new File(Config.getDataDir(), "libs/tis-ibatis");
// File classpathDir = new File("/Users/mozhenghua/Desktop/j2ee_solution/project/tis-ibatis/target/dependency");
JavaCompilerProcess daoCompilerPackageProcess = new JavaCompilerProcess(facadeDataSource.dbMeta, properties.getDaoDir(), classpathDir);
// 打包,生成jar包
daoCompilerPackageProcess.compileAndBuildJar();
// }
}
} catch (Exception e) {
// 将文件夹清空
FileUtils.forceDelete(properties.getDaoDir());
throw new RuntimeException("dao path:" + properties.getDaoDir(), e);
}
}
if (daoFacadeList.size() < 1) {
throw new IllegalStateException("daoFacadeList can not small than 1");
}
daoFacadeList.stream().forEach((r) -> {
FacadeContext fc = new FacadeContext();
fc.setFacadeInstanceName(r.getFacadeInstanceName());
fc.setFullFacadeClassName(r.getFacadeFullClassName());
fc.setFacadeInterfaceName(r.getFacadeInterface());
indexStreamCodeGenerator.getFacadeList().add(fc);
});
// return dbNameMap;
}
use of com.qlangtech.tis.TIS in project plugins by qlangtech.
the class TISFlinClassLoaderFactory method buildClientLoaderFactory.
// public static void main(String[] args) throws Exception {
// File f = new File("/opt/data/tis/cfg_repo/streamscript/mysql_elastic/20210629113249/mysql_elastic-inc.jar");
// try (JarInputStream jarReader = new JarInputStream(FileUtils.openInputStream(f))) {
// Manifest manifest = jarReader.getManifest();
// Attributes pluginInventory = manifest.getAttributes("plugin_inventory");
// if (pluginInventory == null) {
// throw new IllegalStateException("plugin inventory can not be empty in lib:" + f);
// }
// for (Map.Entry<Object, Object> pluginDesc : pluginInventory.entrySet()) {
// // pluginManager.dynamicLoadPlugin(String.valueOf(pluginDesc.getKey()));
// }
// }
// }
@Override
public BlobLibraryCacheManager.ClassLoaderFactory buildClientLoaderFactory(FlinkUserCodeClassLoaders.ResolveOrder classLoaderResolveOrder, String[] alwaysParentFirstPatterns, @Nullable Consumer<Throwable> exceptionHander, boolean checkClassLoaderLeak) {
this.makeDataDirUseable();
ClassLoader parentClassLoader = TIS.get().getPluginManager().uberClassLoader;
return (libraryURLs) -> {
return FlinkUserCodeClassLoaders.create(classLoaderResolveOrder, libraryURLs, parentClassLoader, alwaysParentFirstPatterns, NOOP_EXCEPTION_HANDLER, checkClassLoaderLeak);
};
}
Aggregations