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