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;
}
}
}
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"));
}
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);
}
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);
}
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;
}
Aggregations