Skip to content

Commit

Permalink
get host from config when is not in docker container
Browse files Browse the repository at this point in the history
  • Loading branch information
baisui1981 committed Apr 21, 2024
1 parent f51d0cd commit 8df85f3
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 105 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import com.qlangtech.tis.config.BasicConfig;
import com.qlangtech.tis.org.apache.commons.io.FileUtils;
import com.qlangtech.tis.realtime.utils.NetUtils;
import com.qlangtech.tis.utils.TisMetaProps;
import com.qlangtech.tis.web.start.TisAppLaunch;
import com.qlangtech.tis.web.start.TisSubModule;
Expand Down Expand Up @@ -300,6 +301,7 @@ private Config() {

// this.zkHost = p.getString(KEY_ZK_HOST, true);
// = p.getString(KEY_ASSEMBLE_HOST, true);
// boolean inDocker = BasicConfig.inDockerContainer();
this.assembleHost = (propGetter.getString(KEY_ASSEMBLE_HOST, true));
this.tisHost = propGetter.getString(KEY_TIS_HOST, true);
this.runtime = propGetter.getString(KEY_RUNTIME, true);
Expand Down Expand Up @@ -492,10 +494,9 @@ protected String getProp(String key) {
try {
ResourceBundle bundle = ResourceBundle.getBundle(bundlePath);
final ClassLoader classLoader = Config.class.getClassLoader();
return new P() {
return new LocalResBasedPropertyGetter() {
@Override
protected InputStream getOriginSource() {

InputStream source = classLoader.getResourceAsStream(bundlePathClasspath);
if (source == null) {
throw new NullPointerException("bundlePathClasspath:"
Expand All @@ -506,7 +507,7 @@ protected InputStream getOriginSource() {
}

@Override
protected String getProp(String key) {
protected String getPropValue(String key) {
return bundle.getString(key);
}
};
Expand All @@ -520,7 +521,7 @@ protected String getProp(String key) {
props.load(input);
}
TisAppLaunch.setTest(true);
return new P() {
return new LocalResBasedPropertyGetter() {
@Override
protected InputStream getOriginSource() {
try {
Expand All @@ -529,9 +530,8 @@ protected InputStream getOriginSource() {
throw new RuntimeException(e);
}
}

@Override
protected String getProp(String key) {
protected String getPropValue(String key) {
return props.getProperty(key);
}
};
Expand Down Expand Up @@ -572,6 +572,21 @@ public final String getString(String key, boolean notEmpty) {
protected abstract InputStream getOriginSource();
}


private static abstract class LocalResBasedPropertyGetter extends P {
@Override
protected final String getProp(String key) {
if (KEY_ASSEMBLE_HOST.equals(key) || KEY_TIS_HOST.equals(key)) {
if (BasicConfig.inDockerContainer()) {
return NetUtils.getHost();
}
}

return this.getPropValue(key);
}
protected abstract String getPropValue(String key);
}

public static String getGenerateParentPackage() {
return GENERATE_PARENT_PACKAGE;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@
* @date 2016年8月4日
*/
public class CoreAction extends BasicModule {

private static final Logger logger = LoggerFactory.getLogger(CoreAction.class);
public static final String ADMIN_COLLECTION_PATH = "/solr/admin/collections";
public static final String CREATE_COLLECTION_PATH = ADMIN_COLLECTION_PATH + "?action=CREATE&name=";
public static final String DEFAULT_SOLR_CONFIG = "tis_mock_config";
Expand Down Expand Up @@ -1136,101 +1136,6 @@ public int getMaxSnapshotId(ServerGroup group, RunContext daoContext) {
return null;
}

// /**
// * 各个副本节点描述信息
// *
// * @return
// * @throws Exception
// */
// private static InstanceDirDesc getInstanceDirDesc(BasicModule module) throws Exception {
// InstanceDirDesc dirDesc = new InstanceDirDesc();
// dirDesc.setValid(false);
// DocCollection collection = module.getIndex();
// final Set<String> instanceDir = new HashSet<String>();
// if (collection.getSlices().isEmpty()) {
// dirDesc.setDesc("实例尚未创建,未发现副本节点");
// return dirDesc;
// }
// boolean hasGetAllCount = false;
// URL url = null;
// for (Slice slice : collection.getSlices()) {
// for (final Replica replica : slice.getReplicas()) {
// if (!hasGetAllCount) {
// dirDesc.setAllcount(getAllRowsCount(collection.getName(), replica.getCoreUrl()));
// hasGetAllCount = true;
// }
// //ZkCoreNodeProps.getCoreUrl
// url = new URL(replica.getCoreUrl() + "admin/mbeans?stats=true&cat=CORE&key=core&wt=xml");
// // http:https://192.168.28.200:8080/solr/search4supplyGoods2_shard1_replica_n1/admin/mbeans?stats=true&cat=CORE&key=core&wt=xml
// ConfigFileContext.processContent(url, new StreamProcess<Object>() {
//
// @Override
// @SuppressWarnings("all")
// public Object p(int s, InputStream stream, Map<String, List<String>> headerFields) {
// SimpleOrderedMap result = (SimpleOrderedMap) RESPONSE_PARSER.processResponse(stream, TisUTF8.getName());
// final SimpleOrderedMap mbeans = (SimpleOrderedMap) result.get("solr-mbeans");
// SimpleOrderedMap core = (SimpleOrderedMap) ((SimpleOrderedMap) mbeans.get("CORE")).get("core");
// SimpleOrderedMap status = ((SimpleOrderedMap) core.get("stats"));
// // core 节点刚创建status为空
// if (status == null) {
// return null;
// }
// String indexDir = StringUtils.substringAfterLast((String) status.get("CORE.indexDir"), "/");
// instanceDir.add(indexDir);
// ReplicState replicState = new ReplicState();
// replicState.setIndexDir(indexDir);
// replicState.setValid(StringUtils.isNotBlank(indexDir));
// if (StringUtils.isBlank(indexDir)) {
// replicState.setInvalidDesc("未完成全量构建");
// }
// replicState.setNodeName(StringUtils.substringBefore(replica.getNodeName(), ":"));
// ;
// replicState.setCoreName(StringUtils.substringAfter((String) core.get("class"), "_"));
// replicState.setState(replica.getState().toString());
// replicState.setLeader(replica.getBool("leader", false));
// dirDesc.addReplicState(slice.getName(), replicState);
// return null;
// }
// });
// }
// }
// final StringBuffer replicDirDesc = new StringBuffer();
// if (instanceDir.size() > 1) {
// replicDirDesc.append("(");
// int count = 0;
// for (String d : instanceDir) {
// replicDirDesc.append(d);
// if (++count < instanceDir.size()) {
// replicDirDesc.append(",");
// }
// }
// replicDirDesc.append(")");
// dirDesc.setDesc("副本目录不一致,分别为:" + replicDirDesc);
// } else if (instanceDir.size() == 1) {
// if (dirDesc.isAllReplicValid()) {
// dirDesc.setValid(true);
// for (String d : instanceDir) {
// dirDesc.setDesc("所有副本目录为:" + d);
// break;
// }
// } else {
// dirDesc.setValid(false);
// dirDesc.setDesc(dirDesc.invalidDesc().toString());
// }
// } else {
// dirDesc.setDesc("副本目录数异常,size:" + instanceDir.size());
// }
// return dirDesc;
// }

// public static long getAllRowsCount(String collectionName, String coreURL) throws SolrServerException, IOException {
// QueryCloudSolrClient solrClient = new QueryCloudSolrClient(coreURL);
// SolrQuery query = new SolrQuery();
// query.setRows(0);
// query.setQuery("*:*");
// return solrClient.query(collectionName, query).getResults().getNumFound();
// }

/**
* 删除增量通道
*
Expand All @@ -1243,9 +1148,13 @@ public void doIncrDelete(Context context) throws Exception {
IndexStreamCodeGenerator indexStreamCodeGenerator = getIndexStreamCodeGenerator(this);
indexStreamCodeGenerator.deleteScript();

TISK8sDelegate k8sDelegate = TISK8sDelegate.getK8SDelegate(this.getCollectionName());
// 删除增量实例
k8sDelegate.removeIncrProcess();
try {
TISK8sDelegate k8sDelegate = TISK8sDelegate.getK8SDelegate(this.getCollectionName());
// 删除增量实例
k8sDelegate.removeIncrProcess();
} catch (Exception e) {
logger.warn(e.getMessage(),e);
}
}


Expand Down

0 comments on commit 8df85f3

Please sign in to comment.