Search in sources :

Example 6 with Biz

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);
}
Also used : Biz(com.alipay.sofa.ark.spi.model.Biz) HashMap(java.util.HashMap) BizManagerService(com.alipay.sofa.ark.spi.service.biz.BizManagerService) Map(java.util.Map) HashMap(java.util.HashMap)

Example 7 with Biz

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;
}
Also used : Biz(com.alipay.sofa.ark.spi.model.Biz) BizInfo(com.alipay.sofa.ark.spi.model.BizInfo) HashSet(java.util.HashSet)

Example 8 with Biz

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));
}
Also used : Biz(com.alipay.sofa.ark.spi.model.Biz) File(java.io.File) URL(java.net.URL) Plugin(com.alipay.sofa.ark.spi.model.Plugin) Test(org.junit.Test) BaseTest(com.alipay.sofa.ark.container.BaseTest)

Example 9 with Biz

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);
            }
        }
    }
}
Also used : Biz(com.alipay.sofa.ark.spi.model.Biz) ClassLoaderHook(com.alipay.sofa.ark.spi.service.classloader.ClassLoaderHook) ArkLoaderException(com.alipay.sofa.ark.exception.ArkLoaderException) IOException(java.io.IOException)

Example 10 with Biz

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"));
}
Also used : Biz(com.alipay.sofa.ark.spi.model.Biz) BaseTest(com.alipay.sofa.ark.container.BaseTest) Test(org.junit.Test)

Aggregations

Biz (com.alipay.sofa.ark.spi.model.Biz)38 Test (org.junit.Test)14 BaseTest (com.alipay.sofa.ark.container.BaseTest)13 BizModel (com.alipay.sofa.ark.container.model.BizModel)12 ArkRuntimeException (com.alipay.sofa.ark.exception.ArkRuntimeException)6 BizManagerService (com.alipay.sofa.ark.spi.service.biz.BizManagerService)6 Plugin (com.alipay.sofa.ark.spi.model.Plugin)5 AfterBizStartupEvent (com.alipay.sofa.ark.spi.event.biz.AfterBizStartupEvent)3 PluginModel (com.alipay.sofa.ark.container.model.PluginModel)2 ExecutableArchive (com.alipay.sofa.ark.spi.archive.ExecutableArchive)2 PluginArchive (com.alipay.sofa.ark.spi.archive.PluginArchive)2 AfterBizSwitchEvent (com.alipay.sofa.ark.spi.event.biz.AfterBizSwitchEvent)2 BeforeBizStartupEvent (com.alipay.sofa.ark.spi.event.biz.BeforeBizStartupEvent)2 BeforeBizSwitchEvent (com.alipay.sofa.ark.spi.event.biz.BeforeBizSwitchEvent)2 BeforePluginStartupEvent (com.alipay.sofa.ark.spi.event.plugin.BeforePluginStartupEvent)2 EventAdminService (com.alipay.sofa.ark.spi.service.event.EventAdminService)2 URL (java.net.URL)2 HashSet (java.util.HashSet)2 MainMethodRunner (com.alipay.sofa.ark.bootstrap.MainMethodRunner)1 OrderComparator (com.alipay.sofa.ark.common.util.OrderComparator)1