use of com.alipay.sofa.ark.spi.archive.ExecutableArchive in project sofa-ark by alipay.
the class HandleArchiveStage method process.
@Override
public void process(PipelineContext pipelineContext) throws ArkRuntimeException {
try {
if (ArkConfigs.isEmbedEnable()) {
processEmbed(pipelineContext);
return;
}
ExecutableArchive executableArchive = pipelineContext.getExecutableArchive();
List<BizArchive> bizArchives = executableArchive.getBizArchives();
List<PluginArchive> pluginArchives = executableArchive.getPluginArchives();
if (useDynamicConfig()) {
AssertUtils.isFalse(StringUtils.isEmpty(ArkConfigs.getStringValue(Constants.MASTER_BIZ)), "Master biz should be configured when using dynamic config.");
}
int bizCount = 0;
for (BizArchive bizArchive : bizArchives) {
Biz biz = bizFactoryService.createBiz(bizArchive);
if (bizArchive instanceof DirectoryBizArchive) {
if (!((DirectoryBizArchive) bizArchive).isTestMode()) {
bizManagerService.registerBiz(biz);
bizCount += 1;
}
} else if (useDynamicConfig()) {
if (biz.getBizName().equals(ArkConfigs.getStringValue(Constants.MASTER_BIZ))) {
bizManagerService.registerBiz(biz);
bizCount += 1;
} else {
LOGGER.warn("The biz of {} is ignored when using dynamic config.", biz.getIdentity());
}
} else {
if (!isBizExcluded(biz)) {
bizManagerService.registerBiz(biz);
bizCount += 1;
} else {
LOGGER.warn(String.format("The biz of %s is excluded.", biz.getIdentity()));
}
}
}
// master biz should be specified when deploy multi biz, otherwise the only biz would be token as master biz
if (bizCount > 1) {
AssertUtils.isFalse(StringUtils.isEmpty(ArkConfigs.getStringValue(Constants.MASTER_BIZ)), "Master biz should be configured when deploy multi biz.");
String masterBizName = ArkConfigs.getStringValue(Constants.MASTER_BIZ);
for (Biz biz : bizManagerService.getBizInOrder()) {
if (masterBizName.equals(biz.getBizName())) {
ArkClient.setMasterBiz(biz);
}
}
} else {
List<Biz> bizList = bizManagerService.getBizInOrder();
if (!bizList.isEmpty() && StringUtils.isEmpty(ArkConfigs.getStringValue(Constants.MASTER_BIZ))) {
ArkConfigs.putStringValue(Constants.MASTER_BIZ, bizList.get(0).getBizName());
ArkClient.setMasterBiz(bizList.get(0));
}
}
URL[] exportUrls = null;
Set<String> exportPackages = new HashSet<>();
Biz masterBiz = ArkClient.getMasterBiz();
for (BizArchive bizArchive : bizArchives) {
Attributes mainAttributes = bizArchive.getManifest().getMainAttributes();
String bizName = mainAttributes.getValue(ARK_BIZ_NAME);
// extension from master biz
if (bizArchive instanceof JarBizArchive && masterBiz.getBizName().equalsIgnoreCase(bizName)) {
String exportPackageStr = mainAttributes.getValue(INJECT_EXPORT_PACKAGES);
exportPackages.addAll(StringUtils.strToSet(exportPackageStr, MANIFEST_VALUE_SPLIT));
exportUrls = ((JarBizArchive) bizArchive).getExportUrls();
}
}
for (PluginArchive pluginArchive : pluginArchives) {
Plugin plugin = pluginFactoryService.createPlugin(pluginArchive, exportUrls, exportPackages);
if (!isPluginExcluded(plugin)) {
pluginManagerService.registerPlugin(plugin);
} else {
LOGGER.warn(String.format("The plugin of %s is excluded.", plugin.getPluginName()));
}
}
} catch (Throwable ex) {
throw new ArkRuntimeException(ex.getMessage(), ex);
}
}
use of com.alipay.sofa.ark.spi.archive.ExecutableArchive in project sofa-ark by alipay.
the class HandleArchiveStage method processEmbed.
protected void processEmbed(PipelineContext pipelineContext) throws Exception {
ClassLoader masterBizClassLoader = pipelineContext.getClass().getClassLoader();
Biz masterBiz = bizFactoryService.createEmbedMasterBiz(masterBizClassLoader);
bizManagerService.registerBiz(masterBiz);
ArkClient.setMasterBiz(masterBiz);
ArkConfigs.putStringValue(Constants.MASTER_BIZ, masterBiz.getBizName());
ExecutableArchive executableArchive = pipelineContext.getExecutableArchive();
List<PluginArchive> pluginArchives = executableArchive.getPluginArchives();
for (PluginArchive pluginArchive : pluginArchives) {
Plugin plugin = pluginFactoryService.createEmbedPlugin(pluginArchive, masterBizClassLoader);
if (!isPluginExcluded(plugin)) {
pluginManagerService.registerPlugin(plugin);
} else {
LOGGER.warn(String.format("The plugin of %s is excluded.", plugin.getPluginName()));
}
}
return;
}
Aggregations