Search in sources :

Example 31 with Biz

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

the class ArkClient method switchBiz.

/**
 * Active biz with specified bizName and bizVersion
 *
 * @param bizName
 * @param bizVersion
 * @return
 */
public static ClientResponse switchBiz(String bizName, String bizVersion) {
    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!");
    Biz biz = bizManagerService.getBiz(bizName, bizVersion);
    ClientResponse response = new ClientResponse().setCode(ResponseCode.NOT_FOUND_BIZ).setMessage(String.format("Switch biz: %s not found.", BizIdentityUtils.generateBizIdentity(bizName, bizVersion)));
    if (biz != null) {
        if (biz.getBizState() != BizState.ACTIVATED && biz.getBizState() != BizState.DEACTIVATED) {
            response.setCode(ResponseCode.ILLEGAL_STATE_BIZ).setMessage(String.format("Switch Biz: %s's state must not be %s.", biz.getIdentity(), biz.getBizState()));
        } else {
            eventAdminService.sendEvent(new BeforeBizSwitchEvent(biz));
            bizManagerService.activeBiz(bizName, bizVersion);
            eventAdminService.sendEvent(new AfterBizSwitchEvent(biz));
            response.setCode(ResponseCode.SUCCESS).setMessage(String.format("Switch biz: %s is activated.", biz.getIdentity()));
        }
    }
    LOGGER.info(response.getMessage());
    return response;
}
Also used : Biz(com.alipay.sofa.ark.spi.model.Biz) AfterBizSwitchEvent(com.alipay.sofa.ark.spi.event.biz.AfterBizSwitchEvent) BeforeBizSwitchEvent(com.alipay.sofa.ark.spi.event.biz.BeforeBizSwitchEvent)

Example 32 with Biz

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

the class ArkClient method installBiz.

public static ClientResponse installBiz(File bizFile, String[] args) throws Throwable {
    AssertUtils.assertNotNull(bizFactoryService, "bizFactoryService must not be null!");
    AssertUtils.assertNotNull(bizManagerService, "bizFactoryService must not be null!");
    AssertUtils.assertNotNull(bizFile, "bizFile must not be null!");
    long start = System.currentTimeMillis();
    SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss,SSS");
    String startDate = sdf.format(new Date(start));
    Biz biz = bizFactoryService.createBiz(bizFile);
    ClientResponse response = new ClientResponse();
    if (bizManagerService.getBizByIdentity(biz.getIdentity()) != null || !bizManagerService.registerBiz(biz)) {
        return response.setCode(ResponseCode.REPEAT_BIZ).setMessage(String.format("Biz: %s has been installed or registered.", biz.getIdentity()));
    }
    try {
        biz.start(args);
        long end = System.currentTimeMillis();
        response.setCode(ResponseCode.SUCCESS).setMessage(String.format("Install Biz: %s success, cost: %s ms, started at: %s", biz.getIdentity(), end - start, startDate)).setBizInfos(Collections.<BizInfo>singleton(biz));
        LOGGER.info(response.getMessage());
        return response;
    } catch (Throwable throwable) {
        long end = System.currentTimeMillis();
        response.setCode(ResponseCode.FAILED).setMessage(String.format("Install Biz: %s fail,cost: %s ms, started at: %s", biz.getIdentity(), end - start, startDate));
        LOGGER.error(response.getMessage(), throwable);
        try {
            biz.stop();
        } catch (Throwable e) {
            LOGGER.error(String.format("UnInstall Biz: %s fail.", biz.getIdentity()), e);
            throw e;
        } finally {
            bizManagerService.unRegisterBizStrictly(biz.getBizName(), biz.getBizVersion());
        }
        return response;
    }
}
Also used : Biz(com.alipay.sofa.ark.spi.model.Biz) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 33 with Biz

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

the class BizManagerServiceImpl method registerBiz.

@Override
@SuppressWarnings("unchecked")
public boolean registerBiz(Biz biz) {
    AssertUtils.assertNotNull(biz, "Biz must not be null.");
    AssertUtils.isTrue(biz.getBizState() == BizState.RESOLVED, "BizState must be RESOLVED.");
    bizRegistration.putIfAbsent(biz.getBizName(), new ConcurrentHashMap<String, Biz>(16));
    ConcurrentHashMap bizCache = bizRegistration.get(biz.getBizName());
    return bizCache.put(biz.getBizVersion(), biz) == null;
}
Also used : Biz(com.alipay.sofa.ark.spi.model.Biz) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 34 with Biz

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

the class DefaultBizDeployer method unDeploy.

@Override
public void unDeploy() {
    for (Biz biz : bizManagerService.getBizInOrder()) {
        try {
            LOGGER.info(String.format("Begin to stop biz: %s", biz.getBizName()));
            biz.stop();
            LOGGER.info(String.format("Finish to stop biz: %s", biz.getBizName()));
        } catch (Throwable e) {
            LOGGER.error(String.format("stop biz: %s meet error", biz.getBizName()), e);
            throw new ArkRuntimeException(e);
        }
    }
}
Also used : Biz(com.alipay.sofa.ark.spi.model.Biz) ArkRuntimeException(com.alipay.sofa.ark.exception.ArkRuntimeException)

Example 35 with Biz

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

the class DefaultBizDeployer method deploy.

@Override
public void deploy() {
    for (Biz biz : bizManagerService.getBizInOrder()) {
        try {
            LOGGER.info(String.format("Begin to start biz: %s", biz.getBizName()));
            biz.start(arguments);
            LOGGER.info(String.format("Finish to start biz: %s", biz.getBizName()));
        } catch (Throwable e) {
            LOGGER.error(String.format("Start biz: %s meet error", biz.getBizName()), e);
            throw new ArkRuntimeException(e);
        }
    }
}
Also used : Biz(com.alipay.sofa.ark.spi.model.Biz) ArkRuntimeException(com.alipay.sofa.ark.exception.ArkRuntimeException)

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