use of com.alipay.sofa.ark.spi.model.BizInfo in project sofa-ark by alipay.
the class ArkClient method checkBiz.
/**
* Check all {@link com.alipay.sofa.ark.spi.model.BizInfo} with specified bizName and bizVersion
*
* @param bizName
* @param bizVersion
* @return
*/
public static ClientResponse checkBiz(String bizName, String bizVersion) {
AssertUtils.assertNotNull(bizFactoryService, "bizFactoryService must not be null!");
AssertUtils.assertNotNull(bizManagerService, "bizFactoryService must not be null!");
ClientResponse response = new ClientResponse();
Set<BizInfo> bizInfoSet = new HashSet<>();
if (bizName != null && bizVersion != null) {
Biz biz = bizManagerService.getBiz(bizName, bizVersion);
if (biz != null) {
bizInfoSet.add(biz);
}
} else if (bizName != null) {
bizInfoSet.addAll(bizManagerService.getBiz(bizName));
} else {
bizInfoSet.addAll(bizManagerService.getBizInOrder());
}
StringBuilder sb = new StringBuilder();
sb.append(String.format("Biz count=%d", bizInfoSet.size())).append("\n");
for (BizInfo bizInfo : bizInfoSet) {
sb.append(String.format("bizName=%s, bizVersion=%s, bizState=%s", bizInfo.getBizName(), bizInfo.getBizVersion(), bizInfo.getBizState())).append("\n");
}
response.setCode(ResponseCode.SUCCESS).setBizInfos(bizInfoSet).setMessage(sb.toString());
LOGGER.info(String.format("Check Biz: %s", response.getMessage()));
return response;
}
use of com.alipay.sofa.ark.spi.model.BizInfo in project sofa-ark by alipay.
the class ArkClientTest method testInstallBiz.
@Test
public void testInstallBiz() throws Throwable {
ClientResponse response = ArkClient.checkBiz();
Assert.assertEquals(ResponseCode.SUCCESS, response.getCode());
Assert.assertEquals(0, response.getBizInfos().size());
// test install
File bizFile = ArkClient.createBizSaveFile("biz-demo", "1.0.0");
FileUtils.copyInputStreamToFile(bizUrl1.openStream(), bizFile);
response = ArkClient.installBiz(bizFile);
Assert.assertEquals(ResponseCode.SUCCESS, response.getCode());
BizInfo bizInfo = response.getBizInfos().iterator().next();
Assert.assertEquals(BizState.ACTIVATED, bizInfo.getBizState());
// test install biz with same bizName and bizVersion
// test install
File bizFile1 = ArkClient.createBizSaveFile("biz-demo", "1.0.0");
FileUtils.copyInputStreamToFile(bizUrl1.openStream(), bizFile1);
response = ArkClient.installBiz(bizFile1);
Assert.assertEquals(ResponseCode.REPEAT_BIZ, response.getCode());
// test install biz with same bizName and different bizVersion
// response = ArkClient.installBiz(new File(bizUrl2.getFile()));
File bizFile2 = ArkClient.createBizSaveFile("biz-demo", "2.0.0");
FileUtils.copyInputStreamToFile(bizUrl2.openStream(), bizFile2);
response = ArkClient.installBiz(bizFile2);
Assert.assertEquals(ResponseCode.SUCCESS, response.getCode());
bizInfo = response.getBizInfos().iterator().next();
Assert.assertEquals(BizState.DEACTIVATED, bizInfo.getBizState());
// test install biz with same bizName and different bizVersion and active latest
System.setProperty(Constants.ACTIVATE_NEW_MODULE, "true");
System.setProperty(Constants.EMBED_ENABLE, "true");
File bizFile3 = ArkClient.createBizSaveFile("biz-demo", "3.0.0");
FileUtils.copyInputStreamToFile(bizUrl3.openStream(), bizFile3);
response = ArkClient.installBiz(bizFile3);
System.setProperty(Constants.ACTIVATE_NEW_MODULE, "");
System.setProperty(Constants.EMBED_ENABLE, "");
Assert.assertEquals(ResponseCode.SUCCESS, response.getCode());
bizInfo = response.getBizInfos().iterator().next();
Assert.assertEquals(BizState.ACTIVATED, bizInfo.getBizState());
}
use of com.alipay.sofa.ark.spi.model.BizInfo in project sofa-ark by alipay.
the class ArkClientTest method testSwitchBiz.
public void testSwitchBiz() throws Throwable {
testUninstallBiz();
// test switch biz
ClientResponse response = ArkClient.installBiz(new File(bizUrl1.getFile()));
Assert.assertEquals(ResponseCode.SUCCESS, response.getCode());
BizInfo bizInfo = response.getBizInfos().iterator().next();
Assert.assertEquals(BizState.ACTIVATED, bizInfo.getBizState());
response = ArkClient.checkBiz("biz-demo", "2.0.0");
Assert.assertEquals(ResponseCode.SUCCESS, response.getCode());
Assert.assertEquals(1, response.getBizInfos().size());
bizInfo = response.getBizInfos().iterator().next();
Assert.assertEquals(BizState.DEACTIVATED, bizInfo.getBizState());
response = ArkClient.switchBiz("biz-demo", "2.0.0");
Assert.assertEquals(ResponseCode.SUCCESS, response.getCode());
response = ArkClient.switchBiz("biz-demo", "3.0.0");
Assert.assertEquals(ResponseCode.NOT_FOUND_BIZ, response.getCode());
response = ArkClient.checkBiz("biz-demo", "2.0.0");
bizInfo = response.getBizInfos().iterator().next();
Assert.assertEquals(BizState.ACTIVATED, bizInfo.getBizState());
response = ArkClient.checkBiz("biz-demo", "1.0.0");
bizInfo = response.getBizInfos().iterator().next();
Assert.assertEquals(BizState.DEACTIVATED, bizInfo.getBizState());
// Uninstall biz
ArkClient.uninstallBiz("biz-demo", "1.0.0");
ArkClient.uninstallBiz("biz-demo", "2.0.0");
}