Search in sources :

Example 26 with Biz

use of com.alipay.sofa.ark.spi.model.Biz in project sofa-ark by alipay.

the class BizManagerServiceTest method testRemovingAndAddBiz.

@Test
public void testRemovingAndAddBiz() {
    Biz adding = new BizModel().setBizName("test-biz-adding").setBizVersion("1.0.0").setBizState(BizState.ACTIVATED);
    Biz removing = new BizModel().setBizName("test-biz-removing").setBizVersion("1.0.0").setBizState(BizState.RESOLVED);
    bizManagerService.registerBiz(removing);
    ((BizModel) removing).setBizState(BizState.ACTIVATED);
    bizManagerService.removeAndAddBiz(adding, removing);
    List<Biz> biz = bizManagerService.getBiz("test-biz-adding");
    Assert.assertTrue(biz.size() == 1);
    biz = bizManagerService.getBiz("test-biz-removing");
    Assert.assertTrue(biz.size() == 0);
    bizManagerService.unRegisterBiz(adding.getBizName(), adding.getBizVersion());
}
Also used : Biz(com.alipay.sofa.ark.spi.model.Biz) BizModel(com.alipay.sofa.ark.container.model.BizModel) BaseTest(com.alipay.sofa.ark.container.BaseTest) Test(org.junit.Test)

Example 27 with Biz

use of com.alipay.sofa.ark.spi.model.Biz in project sofa-ark by alipay.

the class BizManagerServiceTest method before.

@Before
public void before() {
    super.before();
    Biz biz = new BizModel().setBizName("test-biz").setBizVersion("1.0.0").setBizState(BizState.RESOLVED);
    bizManagerService.registerBiz(biz);
}
Also used : Biz(com.alipay.sofa.ark.spi.model.Biz) BizModel(com.alipay.sofa.ark.container.model.BizModel) Before(org.junit.Before)

Example 28 with Biz

use of com.alipay.sofa.ark.spi.model.Biz in project sofa-ark by alipay.

the class BizManagerServiceTest method testUnRegister.

@Test
public void testUnRegister() {
    Biz biz = bizManagerService.unRegisterBiz("test-biz", "1.0.1");
    Assert.assertNull(biz);
    Assert.assertTrue(bizManagerService.getBiz("test-biz").size() == 1);
    biz = bizManagerService.unRegisterBizStrictly("test-biz", "1.0.0");
    Assert.assertNotNull(biz);
    Assert.assertTrue(bizManagerService.getBiz("test-biz").size() == 0);
    bizManagerService.registerBiz(biz);
    Assert.assertTrue(bizManagerService.getBiz("test-biz").size() == 1);
}
Also used : Biz(com.alipay.sofa.ark.spi.model.Biz) BaseTest(com.alipay.sofa.ark.container.BaseTest) Test(org.junit.Test)

Example 29 with Biz

use of com.alipay.sofa.ark.spi.model.Biz in project sofa-ark by alipay.

the class ClassLoaderServiceTest method testIsDeniedImportClass.

@Test
public void testIsDeniedImportClass() {
    Biz biz = new BizModel().setBizName("mockBiz").setBizVersion("1.0.0").setDenyImportPackages("a.c, a.b.c.*, a.b.c").setDenyImportClasses("").setBizState(BizState.RESOLVED);
    bizManagerService.registerBiz(biz);
    AssertUtils.isFalse(classloaderService.isDeniedImportClass(biz.getIdentity(), "a.c"), "Exception error");
    AssertUtils.isTrue(classloaderService.isDeniedImportClass(biz.getIdentity(), "a.c.E"), "Exception error");
    AssertUtils.isFalse(classloaderService.isDeniedImportClass(biz.getIdentity(), "a.c.e.G"), "Exception error");
    AssertUtils.isTrue(classloaderService.isDeniedImportClass(biz.getIdentity(), "a.b.c.E"), "Exception error");
    AssertUtils.isTrue(classloaderService.isDeniedImportClass(biz.getIdentity(), "a.b.c.e.G"), "Exception error");
    AssertUtils.isFalse(classloaderService.isDeniedImportClass(biz.getIdentity(), "a.b.c"), "Exception error");
}
Also used : Biz(com.alipay.sofa.ark.spi.model.Biz) BizModel(com.alipay.sofa.ark.container.model.BizModel) Test(org.junit.Test) BaseTest(com.alipay.sofa.ark.container.BaseTest)

Example 30 with Biz

use of com.alipay.sofa.ark.spi.model.Biz in project sofa-ark by alipay.

the class ArkClient method uninstallBiz.

/**
 * Uninstall biz.
 *
 * @param bizName
 * @param bizVersion
 * @return
 * @throws Throwable
 */
public static ClientResponse uninstallBiz(String bizName, String bizVersion) throws Throwable {
    AssertUtils.assertNotNull(bizFactoryService, "bizFactoryService must not be null!");
    AssertUtils.assertNotNull(bizManagerService, "bizFactoryService must not be null!");
    AssertUtils.assertNotNull(bizName, "bizName must not be null!");
    AssertUtils.assertNotNull(bizVersion, "bizVersion must not be null!");
    // ignore when uninstall master biz
    if (bizName.equals(ArkConfigs.getStringValue(Constants.MASTER_BIZ))) {
        return new ClientResponse().setCode(ResponseCode.FAILED).setMessage("Master biz must not be uninstalled.");
    }
    Biz biz = bizManagerService.getBiz(bizName, bizVersion);
    ClientResponse response = new ClientResponse().setCode(ResponseCode.NOT_FOUND_BIZ).setMessage(String.format("Uninstall biz: %s not found.", BizIdentityUtils.generateBizIdentity(bizName, bizVersion)));
    if (biz != null) {
        try {
            biz.stop();
        } catch (Throwable throwable) {
            LOGGER.error(String.format("UnInstall Biz: %s fail.", biz.getIdentity()), throwable);
            throw throwable;
        } finally {
            bizManagerService.unRegisterBizStrictly(biz.getBizName(), biz.getBizVersion());
        }
        response.setCode(ResponseCode.SUCCESS).setMessage(String.format("Uninstall biz: %s success.", biz.getIdentity()));
    }
    LOGGER.info(response.getMessage());
    return response;
}
Also used : Biz(com.alipay.sofa.ark.spi.model.Biz)

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