Search in sources :

Example 6 with PostedDSProp

use of com.qlangtech.tis.plugin.ds.PostedDSProp in project tis by qlangtech.

the class HeteroEnum method getPlugins.

/**
 * ref: PluginItems.save()
 *
 * @param pluginContext
 * @param pluginMeta
 * @param
 * @return
 */
public List<T> getPlugins(IPluginContext pluginContext, UploadPluginMeta pluginMeta) {
    IPluginStore store = getPluginStore(pluginContext, pluginMeta);
    if (store == null) {
        return Collections.emptyList();
    }
    // if (this == HeteroEnum.APP_SOURCE) {
    // final String dataxName = (pluginMeta.getExtraParam(DataxUtils.DATAX_NAME));
    // if (StringUtils.isEmpty(dataxName)) {
    // throw new IllegalArgumentException("plugin extra param 'DataxUtils.DATAX_NAME'" + DataxUtils.DATAX_NAME + " can not be null");
    // }
    // store = com.qlangtech.tis.manage.IAppSource.getPluginStore(pluginContext, dataxName);
    // } else if (this == HeteroEnum.DATAX_WRITER || this == HeteroEnum.DATAX_READER) {
    // final String dataxName = pluginMeta.getExtraParam(DataxUtils.DATAX_NAME);
    // if (StringUtils.isEmpty(dataxName)) {
    // throw new IllegalArgumentException("plugin extra param 'DataxUtils.DATAX_NAME': '" + DataxUtils.DATAX_NAME + "' can not be null");
    // }
    // store = (this == HeteroEnum.DATAX_READER) ? DataxReader.getPluginStore(pluginContext, dataxName) : DataxWriter.getPluginStore(pluginContext, dataxName);
    // } else if (pluginContext.isCollectionAware()) {
    // store = TIS.getPluginStore(pluginContext.getCollectionName(), this.extensionPoint);
    // } else if (pluginContext.isDataSourceAware()) {
    // PostedDSProp dsProp = PostedDSProp.parse(pluginMeta);
    // if (StringUtils.isEmpty(dsProp.getDbname())) {
    // return Collections.emptyList();
    // }
    // store = TIS.getDataBasePluginStore(dsProp);
    // } else {
    // store = TIS.getPluginStore(this.extensionPoint);
    // }
    // Objects.requireNonNull(store, "plugin store can not be null");
    List<T> plugins = store.getPlugins();
    if (pluginMeta != null && StringUtils.isNotEmpty(pluginMeta.getTargetPluginDesc())) {
        return plugins.stream().filter((p) -> StringUtils.equals(p.getDescriptor().getDisplayName(), pluginMeta.getTargetPluginDesc())).collect(Collectors.toList());
    }
    return plugins;
}
Also used : StringUtils(org.apache.commons.lang.StringUtils) FlatTableBuilder(com.qlangtech.tis.offline.FlatTableBuilder) IAppSource(com.qlangtech.tis.manage.IAppSource) TIS(com.qlangtech.tis.TIS) ParamsConfig(com.qlangtech.tis.config.ParamsConfig) PostedDSProp(com.qlangtech.tis.plugin.ds.PostedDSProp) ParamsConfigPluginStore(com.qlangtech.tis.plugin.credentials.ParamsConfigPluginStore) DataXJobWorker(com.qlangtech.tis.datax.job.DataXJobWorker) DataxUtils(com.qlangtech.tis.offline.DataxUtils) MQListenerFactory(com.qlangtech.tis.async.message.client.consumer.impl.MQListenerFactory) KeyedPluginStore(com.qlangtech.tis.plugin.KeyedPluginStore) TISTransformerFactory(com.qlangtech.tis.plugin.solr.config.TISTransformerFactory) IPluginStore(com.qlangtech.tis.plugin.IPluginStore) DataSourceFactory(com.qlangtech.tis.plugin.ds.DataSourceFactory) ExtensionList(com.qlangtech.tis.extension.ExtensionList) TISExtension(com.qlangtech.tis.extension.TISExtension) IncrStreamFactory(com.qlangtech.tis.plugin.incr.IncrStreamFactory) DataxWriter(com.qlangtech.tis.datax.impl.DataxWriter) Descriptor(com.qlangtech.tis.extension.Descriptor) IdentityName(com.qlangtech.tis.plugin.IdentityName) FieldTypeFactory(com.qlangtech.tis.plugin.solr.schema.FieldTypeFactory) K8sImage(com.qlangtech.tis.plugin.k8s.K8sImage) IPluginEnum(com.qlangtech.tis.IPluginEnum) QueryParserFactory(com.qlangtech.tis.plugin.solr.config.QueryParserFactory) Collectors(java.util.stream.Collectors) FileSystemFactory(com.qlangtech.tis.offline.FileSystemFactory) Objects(java.util.Objects) List(java.util.List) DataxReader(com.qlangtech.tis.datax.impl.DataxReader) SearchComponentFactory(com.qlangtech.tis.plugin.solr.config.SearchComponentFactory) Collections(java.util.Collections) Describable(com.qlangtech.tis.extension.Describable) IPluginStore(com.qlangtech.tis.plugin.IPluginStore)

Example 7 with PostedDSProp

use of com.qlangtech.tis.plugin.ds.PostedDSProp in project tis by qlangtech.

the class GenerateDAOAndIncrScript method getFacadePluginStore.

private DataSourceFactoryPluginStore getFacadePluginStore(Map.Entry<DBNode, List<String>> entry) {
    DataSourceFactoryPluginStore dbPluginStore;
    dbPluginStore = TIS.getDataBasePluginStore(new PostedDSProp(entry.getKey().getDbName(), DbScope.FACADE));
    return dbPluginStore;
}
Also used : PostedDSProp(com.qlangtech.tis.plugin.ds.PostedDSProp) DataSourceFactoryPluginStore(com.qlangtech.tis.plugin.ds.DataSourceFactoryPluginStore)

Example 8 with PostedDSProp

use of com.qlangtech.tis.plugin.ds.PostedDSProp in project tis by qlangtech.

the class HeteroEnum method getPluginStore.

@Override
public IPluginStore getPluginStore(IPluginContext pluginContext, UploadPluginMeta pluginMeta) {
    IPluginStore store = null;
    if (this == HeteroEnum.APP_SOURCE) {
        final String dataxName = (pluginMeta.getExtraParam(DataxUtils.DATAX_NAME));
        if (StringUtils.isEmpty(dataxName)) {
            throw new IllegalArgumentException("plugin extra param 'DataxUtils.DATAX_NAME'" + DataxUtils.DATAX_NAME + " can not be null");
        }
        store = com.qlangtech.tis.manage.IAppSource.getPluginStore(pluginContext, dataxName);
    } else if (this == HeteroEnum.DATAX_WRITER || this == HeteroEnum.DATAX_READER) {
        // final String dataxName = pluginMeta.getExtraParam(DataxUtils.DATAX_NAME);
        // if (StringUtils.isEmpty(dataxName)) {
        // throw new IllegalArgumentException("plugin extra param 'DataxUtils.DATAX_NAME': '" + DataxUtils.DATAX_NAME + "' can not be null");
        // }
        // (this == HeteroEnum.DATAX_READER) ? DataxReader.getPluginStore(pluginContext, dataxName) : DataxWriter.getPluginStore(pluginContext, dataxName);
        store = getDataXReaderAndWriterStore(pluginContext, this == HeteroEnum.DATAX_READER, pluginMeta);
    } else if (this == PARAMS_CONFIG) {
        return new ParamsConfigPluginStore(pluginMeta);
    } else if (pluginContext.isDataSourceAware()) {
        PostedDSProp dsProp = PostedDSProp.parse(pluginMeta);
        if (StringUtils.isEmpty(dsProp.getDbname())) {
            // Collections.emptyList();
            return null;
        }
        store = TIS.getDataBasePluginStore(dsProp);
    } else {
        if (this.isAppNameAware()) {
            if (!pluginContext.isCollectionAware()) {
                throw new IllegalStateException(this.getExtensionPoint().getName() + " must be collection aware");
            }
            store = TIS.getPluginStore(pluginContext.getCollectionName(), this.extensionPoint);
        } else {
            store = TIS.getPluginStore(this.extensionPoint);
        }
    }
    Objects.requireNonNull(store, "plugin store can not be null");
    return store;
}
Also used : IPluginStore(com.qlangtech.tis.plugin.IPluginStore) PostedDSProp(com.qlangtech.tis.plugin.ds.PostedDSProp) ParamsConfigPluginStore(com.qlangtech.tis.plugin.credentials.ParamsConfigPluginStore)

Example 9 with PostedDSProp

use of com.qlangtech.tis.plugin.ds.PostedDSProp in project tis by qlangtech.

the class PluginItems method save.

public List<Describable> save(Context context) {
    Objects.requireNonNull(this.pluginContext, "pluginContext can not be null");
    if (items == null) {
        throw new IllegalStateException("prop items can not be null");
    }
    Descriptor.ParseDescribable describable = null;
    AttrValMap attrValMap = null;
    List<Descriptor.ParseDescribable<?>> dlist = Lists.newArrayList();
    List<Describable> describableList = Lists.newArrayList();
    if (this.pluginMeta.isAppend()) {
        IPluginStore pluginStore = heteroEnum.getPluginStore(this.pluginContext, this.pluginMeta);
        if (pluginStore != null) {
            List<Describable> plugins = pluginStore.getPlugins();
            boolean firstSkip = false;
            for (Describable p : plugins) {
                if (!firstSkip) {
                    firstSkip = true;
                    Descriptor.ParseDescribable describablesWithMeta = PluginStore.getDescribablesWithMeta(pluginStore, p);
                    dlist.add(describablesWithMeta);
                } else {
                    dlist.add(new Descriptor.ParseDescribable(p));
                }
            }
        }
    }
    for (int i = 0; i < this.items.size(); i++) {
        attrValMap = this.items.get(i);
        /**
         *====================================================
         * 将客户端post数据包装
         *       ======================================================
         */
        describable = attrValMap.createDescribable(pluginContext);
        dlist.add(describable);
        describableList.add((Describable) describable.instance);
    }
    IPluginStoreSave<?> store = null;
    if (heteroEnum == HeteroEnum.APP_SOURCE) {
        for (Descriptor.ParseDescribable<?> d : dlist) {
            if (d.instance instanceof IdentityName) {
                store = IAppSource.getPluginStore(pluginContext, ((IdentityName) d.instance).identityValue());
                break;
            }
        }
        Objects.requireNonNull(store, "plugin type:" + heteroEnum.getIdentity() + " can not find relevant Store");
    } else if (this.pluginContext.isDataSourceAware()) {
        store = new IPluginStoreSave<DataSourceFactory>() {

            @Override
            public boolean setPlugins(IPluginContext pluginContext, Optional<Context> context, List<Descriptor.ParseDescribable<DataSourceFactory>> dlist, boolean update) {
                for (Descriptor.ParseDescribable<DataSourceFactory> plugin : dlist) {
                    PostedDSProp dbExtraProps = PostedDSProp.parse(pluginMeta);
                    if (DbScope.DETAILED == dbExtraProps.getDbType()) {
                        dbExtraProps.setDbname(plugin.instance.identityValue());
                    }
                    boolean success = TIS.getDataBasePluginStore(dbExtraProps).setPlugins(pluginContext, context, Collections.singletonList(plugin), dbExtraProps.isUpdate());
                    if (!success) {
                        return false;
                    }
                }
                return true;
            }
        };
    } else if (heteroEnum == HeteroEnum.DATAX_WRITER || heteroEnum == HeteroEnum.DATAX_READER) {
        // final String dataxName = pluginMeta.getExtraParam(DataxUtils.DATAX_NAME);
        // if (StringUtils.isEmpty(dataxName)) {
        // String saveDbName = pluginMeta.getExtraParam(DataxUtils.DATAX_DB_NAME);
        // if (StringUtils.isNotBlank(saveDbName)) {
        // store = DataxReader.getPluginStore(this.pluginContext, true, saveDbName);
        // } else {
        // throw new IllegalArgumentException("plugin extra param " + DataxUtils.DATAX_NAME + " can not be null");
        // }
        // } else {
        // KeyedPluginStore<?> keyStore = (heteroEnum == HeteroEnum.DATAX_READER)
        // ? DataxReader.getPluginStore(this.pluginContext, dataxName) : DataxWriter.getPluginStore(this.pluginContext, dataxName);
        // store = keyStore;
        // }
        // if ((heteroEnum == HeteroEnum.DATAX_READER)) {
        // for (Descriptor.ParseDescribable<?> dataXReader : dlist) {
        // DataSourceMeta sourceMeta = (DataSourceMeta) dataXReader.instance;
        // pluginContext.setBizResult(context, sourceMeta.getTablesInDB());
        // }
        // }
        store = HeteroEnum.getDataXReaderAndWriterStore(this.pluginContext, this.heteroEnum == HeteroEnum.DATAX_READER, this.pluginMeta);
        Optional<IPropertyType.SubFormFilter> subFormFilter = pluginMeta.getSubFormFilter();
        if (subFormFilter.isPresent()) {
            IPropertyType.SubFormFilter filter = subFormFilter.get();
            Optional<Descriptor> firstDesc = heteroEnum.descriptors().stream().filter((des) -> filter.match((Descriptor) des)).map((des) -> (Descriptor) des).findFirst();
            if (!firstDesc.isPresent()) {
                throw new IllegalStateException("can not find relevant descriptor:" + filter.uploadPluginMeta.toString());
            }
            // Describable p = keyStore.getPlugin();
            // Descriptor des = p.getDescriptor();
            PluginFormProperties pluginProps = firstDesc.get().getPluginFormPropertyTypes(subFormFilter);
            store = pluginProps.accept(new PluginFormProperties.IVisitor() {

                @Override
                public IPluginStoreSave<?> visit(SuFormProperties props) {
                    // 为了在更新插件时候不把plugin上的@SubForm标记的属性覆盖掉,需要先将老的plugin上的值覆盖到新http post过来的反序列化之后的plugin上
                    // IPluginContext pluginContext, String appname, SuFormProperties subfieldForm, Class<TT> clazz
                    Class<Describable> clazz = (Class<Describable>) heteroEnum.getExtensionPoint();
                    // DataxReader.SubFieldFormAppKey<Describable> key
                    // = new DataxReader.SubFieldFormAppKey<>(pluginContext, dataxName, props, clazz);
                    // 
                    DataxReader.SubFieldFormAppKey<Describable> key = HeteroEnum.createDataXReaderAndWriterRelevant(pluginContext, pluginMeta, new HeteroEnum.DataXReaderAndWriterRelevantCreator<DataxReader.SubFieldFormAppKey<Describable>>() {

                        @Override
                        public DataxReader.SubFieldFormAppKey<Describable> dbRelevant(IPluginContext pluginContext, String saveDbName) {
                            return new DataxReader.SubFieldFormAppKey<>(pluginContext, true, saveDbName, props, clazz);
                        }

                        @Override
                        public DataxReader.SubFieldFormAppKey<Describable> appRelevant(IPluginContext pluginContext, String dataxName) {
                            return new DataxReader.SubFieldFormAppKey<>(pluginContext, false, dataxName, props, clazz);
                        }
                    });
                    return KeyedPluginStore.getPluginStore(key);
                }
            });
        }
    } else if (heteroEnum == HeteroEnum.PARAMS_CONFIG) {
        store = new ParamsConfigPluginStore(this.pluginMeta);
    } else if (heteroEnum == HeteroEnum.DATAX_WORKER) {
        if (!this.pluginContext.isCollectionAware()) {
            throw new IllegalStateException("must be collection aware");
        }
        store = DataXJobWorker.getJobWorkerStore(new TargetResName(this.pluginContext.getCollectionName()));
    // } else if (this.pluginContext.isCollectionAware()) {
    // store = TIS.getPluginStore(this.pluginContext.getCollectionName(), heteroEnum.getExtensionPoint());
    } else {
        if (heteroEnum.isAppNameAware()) {
            if (!this.pluginContext.isCollectionAware()) {
                throw new IllegalStateException(heteroEnum.getExtensionPoint().getName() + " must be collection aware");
            }
            store = TIS.getPluginStore(this.pluginContext.getCollectionName(), heteroEnum.getExtensionPoint());
        } else {
            store = TIS.getPluginStore(heteroEnum.getExtensionPoint());
        }
    // if (heteroEnum.isAppNameAware()) {
    // throw new IllegalStateException(heteroEnum.getExtensionPoint().getName() + " must be app name aware");
    // }
    }
    // dlist
    if (!store.setPlugins(pluginContext, Optional.of(context), convert(dlist))) {
        return Collections.emptyList();
    }
    observable.notifyObservers(new PluginItemsSaveEvent(this.pluginContext, this.heteroEnum, describableList));
    return describableList;
}
Also used : OfflineDatasourceAction(com.qlangtech.tis.offline.module.action.OfflineDatasourceAction) java.util(java.util) TargetResName(com.qlangtech.tis.coredefine.module.action.TargetResName) IAppSource(com.qlangtech.tis.manage.IAppSource) TIS(com.qlangtech.tis.TIS) DatasourceDbCriteria(com.qlangtech.tis.workflow.pojo.DatasourceDbCriteria) Option(com.qlangtech.tis.manage.common.Option) PostedDSProp(com.qlangtech.tis.plugin.ds.PostedDSProp) DbScope(com.qlangtech.tis.offline.DbScope) StringUtils(org.apache.commons.lang3.StringUtils) Context(com.alibaba.citrus.turbine.Context) ParamsConfigPluginStore(com.qlangtech.tis.plugin.credentials.ParamsConfigPluginStore) DataXJobWorker(com.qlangtech.tis.datax.job.DataXJobWorker) BasicServlet(com.qlangtech.tis.manage.servlet.BasicServlet) Lists(com.google.common.collect.Lists) IPropertyType(com.qlangtech.tis.extension.IPropertyType) PluginFormProperties(com.qlangtech.tis.extension.PluginFormProperties) DataSourceFactory(com.qlangtech.tis.plugin.ds.DataSourceFactory) GroovyShellEvaluate(com.qlangtech.tis.extension.util.GroovyShellEvaluate) IWorkflowDAOFacade(com.qlangtech.tis.workflow.dao.IWorkflowDAOFacade) com.qlangtech.tis.plugin(com.qlangtech.tis.plugin) Descriptor(com.qlangtech.tis.extension.Descriptor) IPluginEnum(com.qlangtech.tis.IPluginEnum) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) ServletActionContext(org.apache.struts2.ServletActionContext) DataxReader(com.qlangtech.tis.datax.impl.DataxReader) SuFormProperties(com.qlangtech.tis.extension.impl.SuFormProperties) Describable(com.qlangtech.tis.extension.Describable) DataSourceFactory(com.qlangtech.tis.plugin.ds.DataSourceFactory) Describable(com.qlangtech.tis.extension.Describable) PostedDSProp(com.qlangtech.tis.plugin.ds.PostedDSProp) TargetResName(com.qlangtech.tis.coredefine.module.action.TargetResName) SuFormProperties(com.qlangtech.tis.extension.impl.SuFormProperties) DataxReader(com.qlangtech.tis.datax.impl.DataxReader) PluginFormProperties(com.qlangtech.tis.extension.PluginFormProperties) Descriptor(com.qlangtech.tis.extension.Descriptor) IPropertyType(com.qlangtech.tis.extension.IPropertyType) ParamsConfigPluginStore(com.qlangtech.tis.plugin.credentials.ParamsConfigPluginStore)

Example 10 with PostedDSProp

use of com.qlangtech.tis.plugin.ds.PostedDSProp in project tis by qlangtech.

the class SingleTableAppSource method reflectCols.

@Override
public List<ColumnMetaData> reflectCols() {
    DataSourceFactoryPluginStore dataBasePluginStore = TIS.getDataBasePluginStore(new PostedDSProp(db.getName()));
    TISTable table = dataBasePluginStore.loadTableMeta(tabName);
    // });
    return table.getReflectCols();
}
Also used : PostedDSProp(com.qlangtech.tis.plugin.ds.PostedDSProp) DataSourceFactoryPluginStore(com.qlangtech.tis.plugin.ds.DataSourceFactoryPluginStore) TISTable(com.qlangtech.tis.plugin.ds.TISTable)

Aggregations

PostedDSProp (com.qlangtech.tis.plugin.ds.PostedDSProp)10 DataSourceFactoryPluginStore (com.qlangtech.tis.plugin.ds.DataSourceFactoryPluginStore)6 DataSourceFactory (com.qlangtech.tis.plugin.ds.DataSourceFactory)4 TIS (com.qlangtech.tis.TIS)3 Descriptor (com.qlangtech.tis.extension.Descriptor)3 ParamsConfigPluginStore (com.qlangtech.tis.plugin.credentials.ParamsConfigPluginStore)3 Collectors (java.util.stream.Collectors)3 Context (com.alibaba.citrus.turbine.Context)2 Lists (com.google.common.collect.Lists)2 IPluginEnum (com.qlangtech.tis.IPluginEnum)2 DataxReader (com.qlangtech.tis.datax.impl.DataxReader)2 DataXJobWorker (com.qlangtech.tis.datax.job.DataXJobWorker)2 Describable (com.qlangtech.tis.extension.Describable)2 IAppSource (com.qlangtech.tis.manage.IAppSource)2 IPluginStore (com.qlangtech.tis.plugin.IPluginStore)2 TISTable (com.qlangtech.tis.plugin.ds.TISTable)2 List (java.util.List)2 Map (java.util.Map)2 Objects (java.util.Objects)2 StringUtils (org.apache.commons.lang.StringUtils)2