Skip to content

Commit

Permalink
add error prompt for TIS plugin meata load error for net timeout #145
Browse files Browse the repository at this point in the history
  • Loading branch information
baisui1981 committed Oct 21, 2022
1 parent d229e97 commit e511039
Show file tree
Hide file tree
Showing 5 changed files with 203 additions and 70 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package com.qlangtech.tis.extension.impl;

/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* 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.
*/

import com.google.common.collect.Lists;
import com.qlangtech.tis.extension.Describable;
import com.qlangtech.tis.extension.IPropertyType;
import com.qlangtech.tis.plugin.ds.ColumnMetaData;
import com.qlangtech.tis.plugin.ds.DataSourceMeta;
import com.qlangtech.tis.plugin.ds.TableNotFoundException;
import com.qlangtech.tis.sql.parser.tuple.creator.EntityName;
import com.qlangtech.tis.test.TISEasyMock;
import com.qlangtech.tis.util.UploadPluginMeta;
import org.easymock.EasyMock;

import java.sql.Types;
import java.util.List;

/**
* @author: 百岁(baisui@qlangtech.com)
* @create: 2022-10-19 12:31
**/
public class StubSuFormGetterContext {
private final TISEasyMock easyMock;
private MockPlugin metaPlugin;
private UploadPluginMeta param;
final String id1 = "id1";

public StubSuFormGetterContext(TISEasyMock easyMock) {
this.easyMock = easyMock;
this.initSuForm();
}

private void initSuForm() {
this.metaPlugin = easyMock.mock("metaPlugin", MockPlugin.class);
this.param = easyMock.mock("param", UploadPluginMeta.class);

param.putExtraParams(IPropertyType.SubFormFilter.PLUGIN_META_SUBFORM_DETAIL_ID_VALUE, id1);
EasyMock.expectLastCall().times(1);
EasyMock.expect(param.getExtraParam(
IPropertyType.SubFormFilter.PLUGIN_META_SUBFORM_DETAIL_ID_VALUE)).andReturn(id1);

List<ColumnMetaData> cols = Lists.newArrayList();
// (int index, String key, DataType type, boolean pk)
cols.add(new ColumnMetaData(0, "user_id", new com.qlangtech.tis.plugin.ds.DataType(Types.BIGINT), true));
cols.add(new ColumnMetaData(1, "user_name", new com.qlangtech.tis.plugin.ds.DataType(Types.VARBINARY), false));
try {
EasyMock.expect(metaPlugin.getTableMetadata(EntityName.parse(id1))).andReturn(cols);
} catch (TableNotFoundException e) {
throw new RuntimeException(e);
}
}

public void setSuFormGetterContext() {
SuFormProperties.setSuFormGetterContext(metaPlugin, param, id1);
}

private interface MockPlugin extends Describable, DataSourceMeta {

}
}
31 changes: 16 additions & 15 deletions tis-base-test/src/main/java/com/qlangtech/tis/test/TISEasyMock.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* 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 com.qlangtech.tis.test;

Expand All @@ -23,6 +23,7 @@
*/
public interface TISEasyMock {


default void clearMocks() {
EasyMockUtil.clearMocks();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* 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 com.qlangtech.tis.coredefine.module.action;

Expand All @@ -34,6 +34,7 @@
import com.qlangtech.tis.extension.model.UpdateCenter;
import com.qlangtech.tis.extension.model.UpdateSite;
import com.qlangtech.tis.extension.util.PluginExtraProps;
import com.qlangtech.tis.extension.util.TextFile;
import com.qlangtech.tis.install.InstallState;
import com.qlangtech.tis.install.InstallUtil;
import com.qlangtech.tis.manage.common.Config;
Expand Down Expand Up @@ -443,17 +444,49 @@ public void run() {
}
}


/**
* 重新加载updateSite元数据信息
*
* @throws Exception
*/
public void doReloadUpdateSiteMeta(Context context) throws Exception {
UpdateCenter center = TIS.get().getUpdateCenter();
for (UpdateSite usite : center.getSiteList()) {
TextFile textFile = usite.getDataLoadFaildFile();
if (textFile.exists()) {
usite.updateDirectly().get();
}
}
this.doGetAvailablePlugins(context);
}

/**
* 取得当前可以被安装的插件
*
* @param context
*/
public void doGetAvailablePlugins(Context context) {
public void doGetAvailablePlugins(Context context) throws Exception {

List<String> extendpoint = getExtendpointParam();
Pager pager = this.createPager();
pager.setTotalCount(Integer.MAX_VALUE);
List<UpdateSite.Plugin> availables = TIS.get().getUpdateCenter().getAvailables();
UpdateCenter center = TIS.get().getUpdateCenter();
List<UpdateSite.Plugin> availables = center.getAvailables();
if (CollectionUtils.isEmpty(availables)) {
for (UpdateSite usite : center.getSiteList()) {
TextFile textFile = usite.getDataLoadFaildFile();
if (textFile.exists()) {

Map<String, Object> err = Maps.newHashMap();
err.put("updateSiteLoadErr", true);
err.put(IMessageHandler.ACTION_ERROR_MSG, textFile.read());
this.setBizResult(context, new PaginationResult(pager, availables, err));
return;
}
}
}

if (CollectionUtils.isNotEmpty(extendpoint)) {
availables = availables.stream().filter((plugin) -> {
return CollectionUtils.containsAny(plugin.extendPoints.keySet(), extendpoint);
Expand Down Expand Up @@ -680,7 +713,7 @@ public static PluginItemsParser parsePluginItems(BasicModule module, UploadPlugi
IPluginEnum hEnum = pluginMeta.getHeteroEnum();
//context.put(KEY_VALIDATE_PLUGIN_INDEX, new Integer(pluginIndex));
PluginItems pluginItems = new PluginItems(module, pluginMeta);
List<AttrValMap> describableAttrValMapList = AttrValMap.describableAttrValMapList( itemsArray, subFormFilter);
List<AttrValMap> describableAttrValMapList = AttrValMap.describableAttrValMapList(itemsArray, subFormFilter);
if (pluginMeta.isRequired() && describableAttrValMapList.size() < 1) {
module.addErrorMessage(context, "请设置'" + hEnum.getCaption() + "'表单内容");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* 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 com.qlangtech.tis.datax.impl;

Expand Down Expand Up @@ -270,11 +270,10 @@ public void signDirty() {
// 标记可以在PluginStore中被剔出了
this.dirty = true;
}

//IPluginStore.Recyclable stop
@Override
public final Descriptor<DataxReader> getDescriptor() {
Descriptor<DataxReader> descriptor = TIS.get().getDescriptor(this.getClass());
Objects.requireNonNull(descriptor, "class:" + this.getClass() + " relevant descriptor can not be null");
Class<BaseDataxReaderDescriptor> expectClass = getExpectDescClass();
if (!(expectClass.isAssignableFrom(descriptor.getClass()))) {
throw new IllegalStateException(descriptor.getClass() + " must implement the Descriptor of " + expectClass.getName());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* 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 com.qlangtech.tis.extension.model;

Expand Down Expand Up @@ -145,7 +145,22 @@ public Future<FormValidation> updateDirectly(final boolean signatureCheck) {
return UpdateCenter.updateService.submit(new Callable<FormValidation>() {
@Override
public FormValidation call() throws Exception {
return updateDirectlyNow(signatureCheck);
TextFile faildSignal = getDataLoadFaildFile();
boolean faild = false;
try {
return updateDirectlyNow(signatureCheck);
} catch (Exception e) {
faild = true;
faildSignal.write(e.getMessage());
throw e;
} finally {
if (!faild) {
try {
faildSignal.delete();
} catch (Throwable e) {
}
}
}
}
});
} else {
Expand All @@ -163,7 +178,7 @@ public String getUrl() {
return this.url;
}

public FormValidation updateDirectlyNow(boolean signatureCheck) throws IOException {
private FormValidation updateDirectlyNow(boolean signatureCheck) throws IOException {
String siteCfgUrl = getUrl() + "?id=" + URLEncoder.encode(getId(), "UTF-8") + "&version=" + URLEncoder.encode(TIS.VERSION, "UTF-8");
LOGGER.info("siteCfgUrl:{}", siteCfgUrl);
return updateData(HttpUtils.get( //
Expand Down Expand Up @@ -796,15 +811,15 @@ public DftCoord(String pluginName, JSONObject meta) {
// "url":"http://mirror.qlangtech.com/3.6.0/tis-plugin/tis-datax-hdfs-plugin/tis-datax-hdfs-plugin_hadoop_2.7.3.tpi"
// },
this.pluginName = pluginName;
this.classifier = PluginClassifier.create(meta.getString("classifier"));
this.classifier = PluginClassifier.create(meta.getString("classifier"));
this.sha1 = meta.getString("sha1");
this.sha256 = meta.getString("sha256");
this.size = meta.getLongValue("size");

this.sizeLiteral = FileUtils.byteCountToDisplaySize(this.size);

try {
this.downloadUrl = new URL(meta.getString("url"));
this.downloadUrl = new URL(meta.getString("downloadUrl"));
} catch (MalformedURLException e) {
throw new RuntimeException(e);
}
Expand Down Expand Up @@ -1352,7 +1367,15 @@ public boolean isRelevantToVersion(VersionNumber version) {
* This is where we store the update center data.
*/
private TextFile getDataFile() {
return new TextFile(new File(TIS.pluginCfgRoot, "updates/" + getId() + ".json"));
return new TextFile(getFile(getId() + ".json"));
}

private static File getFile(String name) {
return new File(TIS.pluginCfgRoot, "updates/" + name);
}

public TextFile getDataLoadFaildFile() {
return new TextFile(getFile(getId() + ".error"));
}

public boolean existLocal() {
Expand Down

0 comments on commit e511039

Please sign in to comment.