Search in sources :

Example 1 with BizManagerService

use of com.alipay.sofa.ark.spi.service.biz.BizManagerService in project sofa-ark by alipay.

the class BizModel method start.

@Override
public void start(String[] args) throws Throwable {
    AssertUtils.isTrue(bizState == BizState.RESOLVED, "BizState must be RESOLVED");
    if (mainClass == null) {
        throw new ArkRuntimeException(String.format("biz: %s has no main method", getBizName()));
    }
    ClassLoader oldClassLoader = ClassLoaderUtils.pushContextClassLoader(this.classLoader);
    EventAdminService eventAdminService = ArkServiceContainerHolder.getContainer().getService(EventAdminService.class);
    try {
        eventAdminService.sendEvent(new BeforeBizStartupEvent(this));
        resetProperties();
        if (!isMasterBizAndEmbedEnable()) {
            long start = System.currentTimeMillis();
            MainMethodRunner mainMethodRunner = new MainMethodRunner(mainClass, args);
            mainMethodRunner.run();
            // this can trigger health checker handler
            eventAdminService.sendEvent(new AfterBizStartupEvent(this));
            LOGGER.info("Ark biz {} started in {} ms", getIdentity(), (System.currentTimeMillis() - start));
        }
    } catch (Throwable e) {
        bizState = BizState.BROKEN;
        throw e;
    } finally {
        ClassLoaderUtils.popContextClassLoader(oldClassLoader);
    }
    BizManagerService bizManagerService = ArkServiceContainerHolder.getContainer().getService(BizManagerService.class);
    if (Boolean.getBoolean(Constants.ACTIVATE_NEW_MODULE)) {
        Biz currentActiveBiz = bizManagerService.getActiveBiz(bizName);
        if (currentActiveBiz == null) {
            bizState = BizState.ACTIVATED;
        } else {
            ((BizModel) currentActiveBiz).setBizState(BizState.DEACTIVATED);
            bizState = BizState.ACTIVATED;
        }
    } else {
        if (bizManagerService.getActiveBiz(bizName) == null) {
            bizState = BizState.ACTIVATED;
        } else {
            bizState = BizState.DEACTIVATED;
        }
    }
}
Also used : BeforeBizStartupEvent(com.alipay.sofa.ark.spi.event.biz.BeforeBizStartupEvent) MainMethodRunner(com.alipay.sofa.ark.bootstrap.MainMethodRunner) Biz(com.alipay.sofa.ark.spi.model.Biz) EventAdminService(com.alipay.sofa.ark.spi.service.event.EventAdminService) AfterBizStartupEvent(com.alipay.sofa.ark.spi.event.biz.AfterBizStartupEvent) AbstractClasspathClassLoader(com.alipay.sofa.ark.container.service.classloader.AbstractClasspathClassLoader) BizManagerService(com.alipay.sofa.ark.spi.service.biz.BizManagerService) ArkRuntimeException(com.alipay.sofa.ark.exception.ArkRuntimeException)

Example 2 with BizManagerService

use of com.alipay.sofa.ark.spi.service.biz.BizManagerService in project sofa-ark by alipay.

the class OperationTransformerTest method testTransformUnstableState.

@Test
public void testTransformUnstableState() {
    Exception ex = null;
    try {
        List<Biz> bizList = new ArrayList<>();
        Biz biz1 = Mockito.mock(Biz.class);
        Biz biz2 = Mockito.mock(Biz.class);
        Biz biz3 = Mockito.mock(Biz.class);
        bizList.add(biz1);
        bizList.add(biz2);
        bizList.add(biz3);
        when(biz1.getBizName()).thenReturn("nameA");
        when(biz1.getBizVersion()).thenReturn("vA");
        when(biz1.getBizState()).thenReturn(BizState.ACTIVATED);
        when(biz1.getBizName()).thenReturn("nameA");
        when(biz1.getBizVersion()).thenReturn("vB");
        when(biz1.getBizState()).thenReturn(BizState.RESOLVED);
        when(biz1.getBizName()).thenReturn("nameB");
        when(biz1.getBizVersion()).thenReturn("vA");
        when(biz1.getBizState()).thenReturn(BizState.ACTIVATED);
        PluginContext pluginContext = Mockito.mock(PluginContext.class);
        ServiceReference serviceReference = Mockito.mock(ServiceReference.class);
        BizManagerService bizManagerService = Mockito.mock(BizManagerService.class);
        when(serviceReference.getService()).thenReturn(bizManagerService);
        when(pluginContext.referenceService(any(Class.class))).thenReturn(serviceReference);
        when(bizManagerService.getBizInOrder()).thenReturn(bizList);
        OperationTransformer.transformToBizOperation("nameA:vA:activated;nameA:vB:deactivated;nameB:vB:activated", pluginContext);
    } catch (Exception e) {
        ex = e;
    }
    Assert.assertNotNull(ex);
    Assert.assertTrue(ex.getMessage().contains("Exist illegal biz"));
}
Also used : Biz(com.alipay.sofa.ark.spi.model.Biz) PluginContext(com.alipay.sofa.ark.spi.model.PluginContext) ArrayList(java.util.ArrayList) BizManagerService(com.alipay.sofa.ark.spi.service.biz.BizManagerService) ServiceReference(com.alipay.sofa.ark.spi.registry.ServiceReference) Test(org.junit.Test)

Example 3 with BizManagerService

use of com.alipay.sofa.ark.spi.service.biz.BizManagerService 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 4 with BizManagerService

use of com.alipay.sofa.ark.spi.service.biz.BizManagerService in project sofa-ark by alipay.

the class BizClassloaderTest method before.

@Before
public void before() {
    ArkServiceContainer arkServiceContainer = new ArkServiceContainer();
    arkServiceContainer.start();
    pluginManagerService = ArkServiceContainerHolder.getContainer().getService(PluginManagerService.class);
    pluginDeployService = ArkServiceContainerHolder.getContainer().getService(PluginDeployService.class);
    classloaderService = ArkServiceContainerHolder.getContainer().getService(ClassloaderService.class);
    bizManagerService = ArkServiceContainerHolder.getContainer().getService(BizManagerService.class);
}
Also used : PluginManagerService(com.alipay.sofa.ark.spi.service.plugin.PluginManagerService) PluginDeployService(com.alipay.sofa.ark.spi.service.plugin.PluginDeployService) ClassloaderService(com.alipay.sofa.ark.spi.service.classloader.ClassloaderService) BizManagerService(com.alipay.sofa.ark.spi.service.biz.BizManagerService) ArkServiceContainer(com.alipay.sofa.ark.container.service.ArkServiceContainer) Before(org.junit.Before)

Example 5 with BizManagerService

use of com.alipay.sofa.ark.spi.service.biz.BizManagerService in project sofa-ark by alipay.

the class NoneDelegateTestClassLoader method createTestBiz.

private Biz createTestBiz(String bizIdentity) {
    String[] bizNameAndVersion = bizIdentity.split(":");
    if (bizNameAndVersion.length != 2) {
        throw new ArkRuntimeException("error bizIdentity format.");
    }
    BizManagerService bizManagerService = ArkServiceContainerHolder.getContainer().getService(BizManagerService.class);
    Biz testBiz = new BizModel().setBizName(bizNameAndVersion[0]).setBizVersion(bizNameAndVersion[1]).setClassLoader(this).setDenyImportPackages("").setDenyImportClasses("").setDenyImportResources("").setBizState(BizState.RESOLVED);
    bizManagerService.registerBiz(testBiz);
    return testBiz;
}
Also used : Biz(com.alipay.sofa.ark.spi.model.Biz) BizModel(com.alipay.sofa.ark.container.model.BizModel) BizManagerService(com.alipay.sofa.ark.spi.service.biz.BizManagerService) ArkRuntimeException(com.alipay.sofa.ark.exception.ArkRuntimeException)

Aggregations

BizManagerService (com.alipay.sofa.ark.spi.service.biz.BizManagerService)8 Biz (com.alipay.sofa.ark.spi.model.Biz)6 BizModel (com.alipay.sofa.ark.container.model.BizModel)3 ArkRuntimeException (com.alipay.sofa.ark.exception.ArkRuntimeException)3 AbstractClasspathClassLoader (com.alipay.sofa.ark.container.service.classloader.AbstractClasspathClassLoader)2 EventAdminService (com.alipay.sofa.ark.spi.service.event.EventAdminService)2 MainMethodRunner (com.alipay.sofa.ark.bootstrap.MainMethodRunner)1 ArkServiceContainer (com.alipay.sofa.ark.container.service.ArkServiceContainer)1 AfterBizStartupEvent (com.alipay.sofa.ark.spi.event.biz.AfterBizStartupEvent)1 AfterBizStopEvent (com.alipay.sofa.ark.spi.event.biz.AfterBizStopEvent)1 BeforeBizRecycleEvent (com.alipay.sofa.ark.spi.event.biz.BeforeBizRecycleEvent)1 BeforeBizStartupEvent (com.alipay.sofa.ark.spi.event.biz.BeforeBizStartupEvent)1 BeforeBizStopEvent (com.alipay.sofa.ark.spi.event.biz.BeforeBizStopEvent)1 PluginContext (com.alipay.sofa.ark.spi.model.PluginContext)1 ServiceReference (com.alipay.sofa.ark.spi.registry.ServiceReference)1 ClassloaderService (com.alipay.sofa.ark.spi.service.classloader.ClassloaderService)1 PluginDeployService (com.alipay.sofa.ark.spi.service.plugin.PluginDeployService)1 PluginManagerService (com.alipay.sofa.ark.spi.service.plugin.PluginManagerService)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1