use of com.alipay.sofa.ark.spi.model.Biz in project sofa-ark by alipay.
the class OperationTransformer method transformToBizOperation.
/**
* transform config into biz operation
*
* @param config
* @return
*/
public static List<BizOperation> transformToBizOperation(String config, PluginContext pluginContext) throws IllegalStateException {
BizManagerService bizManagerService = pluginContext.referenceService(BizManagerService.class).getService();
Map<String, Map<String, BizState>> currentBizState = new HashMap<>();
for (Biz biz : bizManagerService.getBizInOrder()) {
if (!BizState.ACTIVATED.equals(biz.getBizState()) && !BizState.DEACTIVATED.equals(biz.getBizState())) {
throw new IllegalStateException(String.format("Exist illegal biz: %s, please wait.", biz));
}
if (biz.getBizName().equals(ArkConfigs.getStringValue(Constants.MASTER_BIZ))) {
continue;
} else if (currentBizState.get(biz.getBizName()) == null) {
currentBizState.put(biz.getBizName(), new HashMap<String, BizState>());
}
currentBizState.get(biz.getBizName()).put(biz.getBizVersion(), biz.getBizState());
}
return doTransformToBizOperation(config, currentBizState);
}
use of com.alipay.sofa.ark.spi.model.Biz in project sofa-ark by alipay.
the class ArkClient method checkBiz.
/**
* Check all {@link com.alipay.sofa.ark.spi.model.BizInfo} with specified bizName and bizVersion
*
* @param bizName
* @param bizVersion
* @return
*/
public static ClientResponse checkBiz(String bizName, String bizVersion) {
AssertUtils.assertNotNull(bizFactoryService, "bizFactoryService must not be null!");
AssertUtils.assertNotNull(bizManagerService, "bizFactoryService must not be null!");
ClientResponse response = new ClientResponse();
Set<BizInfo> bizInfoSet = new HashSet<>();
if (bizName != null && bizVersion != null) {
Biz biz = bizManagerService.getBiz(bizName, bizVersion);
if (biz != null) {
bizInfoSet.add(biz);
}
} else if (bizName != null) {
bizInfoSet.addAll(bizManagerService.getBiz(bizName));
} else {
bizInfoSet.addAll(bizManagerService.getBizInOrder());
}
StringBuilder sb = new StringBuilder();
sb.append(String.format("Biz count=%d", bizInfoSet.size())).append("\n");
for (BizInfo bizInfo : bizInfoSet) {
sb.append(String.format("bizName=%s, bizVersion=%s, bizState=%s", bizInfo.getBizName(), bizInfo.getBizVersion(), bizInfo.getBizState())).append("\n");
}
response.setCode(ResponseCode.SUCCESS).setBizInfos(bizInfoSet).setMessage(sb.toString());
LOGGER.info(String.format("Check Biz: %s", response.getMessage()));
return response;
}
use of com.alipay.sofa.ark.spi.model.Biz in project sofa-ark by alipay.
the class BizFactoryServiceTest method test.
@Test
public void test() throws Throwable {
ClassLoader cl = Thread.currentThread().getContextClassLoader();
URL samplePlugin = cl.getResource("sample-plugin.jar");
Plugin plugin = pluginFactoryService.createPlugin(new File(samplePlugin.getFile()));
pluginManagerService.registerPlugin(plugin);
URL sampleBiz = cl.getResource("sample-biz.jar");
Biz biz = bizFactoryService.createBiz(new File(sampleBiz.getFile()));
bizManagerService.registerBiz(biz);
Assert.assertNotNull(biz);
Assert.assertNotNull(biz.getBizClassLoader().getResource(Constants.ARK_PLUGIN_MARK_ENTRY));
}
use of com.alipay.sofa.ark.spi.model.Biz in project sofa-ark by alipay.
the class BizClassLoader method loadBizClassLoaderHook.
private void loadBizClassLoaderHook() {
if (!skipLoadHook.get()) {
synchronized (lock) {
if (isHookLoaded.compareAndSet(false, true)) {
bizClassLoaderHook = ArkServiceLoader.loadExtensionFromArkBiz(ClassLoaderHook.class, BIZ_CLASS_LOADER_HOOK, bizIdentity);
Biz masterBiz = ArkClient.getMasterBiz();
if (bizClassLoaderHook == null && masterBiz != null && !masterBiz.getIdentity().equals(bizIdentity)) {
ClassLoader masterClassLoader = masterBiz.getBizClassLoader();
String defaultBizClassloaderHook = System.getProperty(BIZ_CLASS_LOADER_HOOK_DIR);
if (!StringUtils.isEmpty(defaultBizClassloaderHook)) {
try {
bizClassLoaderHook = (ClassLoaderHook<Biz>) masterClassLoader.loadClass(defaultBizClassloaderHook).newInstance();
} catch (Exception e) {
throw new RuntimeException(String.format("can not find master classloader hook: %s", defaultBizClassloaderHook), e);
}
}
}
skipLoadHook.set(true);
}
}
}
}
use of com.alipay.sofa.ark.spi.model.Biz in project sofa-ark by alipay.
the class BizCommandProviderTest method testUninstallMasterBiz.
@Test
public void testUninstallMasterBiz() {
ArkConfigs.putStringValue(Constants.MASTER_BIZ, "B1");
Biz bizA1 = ((MockBiz) bizManagerService.getBizByIdentity("A1:V1")).setBizState(BizState.ACTIVATED);
Biz bizA2 = ((MockBiz) bizManagerService.getBizByIdentity("A1:V2")).setBizState(BizState.DEACTIVATED);
Biz bizB1 = ((MockBiz) bizManagerService.getBizByIdentity("B1:V1")).setBizState(BizState.ACTIVATED);
bizCommandProvider.handleCommand("biz -u B1:V1");
sleep(200);
Assert.assertTrue(bizA1.getBizState().equals(BizState.ACTIVATED));
Assert.assertTrue(bizA2.getBizState().equals(BizState.DEACTIVATED));
Assert.assertTrue(bizB1.getBizState().equals(BizState.ACTIVATED));
Assert.assertNotNull(bizManagerService.getBizByIdentity("B1:V1"));
}
Aggregations