查询资源池

This commit is contained in:
Captain.B 2020-03-24 11:33:07 +08:00
parent fdb6d69050
commit 6589326868
4 changed files with 30 additions and 0 deletions

View File

@ -9,6 +9,7 @@ public class EngineContext {
private String namespace; private String namespace;
private String fileType; private String fileType;
private String content; private String content;
private String resourcePoolId;
private Map<String, Object> properties = new HashMap<>(); private Map<String, Object> properties = new HashMap<>();
private Map<String, String> testData = new HashMap<>(); private Map<String, String> testData = new HashMap<>();
@ -67,4 +68,12 @@ public class EngineContext {
public void setTestData(Map<String, String> testData) { public void setTestData(Map<String, String> testData) {
this.testData = testData; this.testData = testData;
} }
public String getResourcePoolId() {
return resourcePoolId;
}
public void setResourcePoolId(String resourcePoolId) {
this.resourcePoolId = resourcePoolId;
}
} }

View File

@ -79,6 +79,9 @@ public class EngineFactory {
for (int i = 0; i < jsonArray.size(); i++) { for (int i = 0; i < jsonArray.size(); i++) {
final JSONObject jsonObject = jsonArray.getJSONObject(i); final JSONObject jsonObject = jsonArray.getJSONObject(i);
engineContext.addProperty(jsonObject.getString("key"), jsonObject.get("value")); engineContext.addProperty(jsonObject.getString("key"), jsonObject.get("value"));
if (StringUtils.equals(jsonObject.getString("key"), "resourcePoolId")) {
engineContext.setResourcePoolId(jsonObject.getString("value"));
}
} }
} }

View File

@ -4,6 +4,9 @@ import com.alibaba.fastjson.JSON;
import io.fabric8.kubernetes.api.model.ConfigMap; import io.fabric8.kubernetes.api.model.ConfigMap;
import io.fabric8.kubernetes.api.model.ObjectMeta; import io.fabric8.kubernetes.api.model.ObjectMeta;
import io.fabric8.kubernetes.client.KubernetesClient; import io.fabric8.kubernetes.client.KubernetesClient;
import io.metersphere.base.domain.TestResource;
import io.metersphere.base.domain.TestResourcePool;
import io.metersphere.commons.exception.MSException;
import io.metersphere.commons.utils.CommonBeanFactory; import io.metersphere.commons.utils.CommonBeanFactory;
import io.metersphere.commons.utils.LogUtil; import io.metersphere.commons.utils.LogUtil;
import io.metersphere.engine.Engine; import io.metersphere.engine.Engine;
@ -13,19 +16,23 @@ import io.metersphere.engine.kubernetes.crds.jmeter.JmeterSpec;
import io.metersphere.engine.kubernetes.provider.ClientCredential; import io.metersphere.engine.kubernetes.provider.ClientCredential;
import io.metersphere.engine.kubernetes.provider.KubernetesProvider; import io.metersphere.engine.kubernetes.provider.KubernetesProvider;
import io.metersphere.service.TestResourcePoolService; import io.metersphere.service.TestResourcePoolService;
import io.metersphere.service.TestResourceService;
import org.apache.commons.collections.MapUtils; import org.apache.commons.collections.MapUtils;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
public class KubernetesTestEngine implements Engine { public class KubernetesTestEngine implements Engine {
private EngineContext context; private EngineContext context;
private TestResourcePoolService testResourcePoolService; private TestResourcePoolService testResourcePoolService;
private TestResourceService testResourceService;
@Override @Override
public boolean init(EngineContext context) { public boolean init(EngineContext context) {
// todo 初始化操作 // todo 初始化操作
this.context = context; this.context = context;
this.testResourcePoolService = CommonBeanFactory.getBean(TestResourcePoolService.class); this.testResourcePoolService = CommonBeanFactory.getBean(TestResourcePoolService.class);
this.testResourceService = CommonBeanFactory.getBean(TestResourceService.class);
return true; return true;
} }
@ -36,6 +43,11 @@ public class KubernetesTestEngine implements Engine {
LogUtil.warn("Please initial the engine."); LogUtil.warn("Please initial the engine.");
return; return;
} }
TestResourcePool resourcePool = testResourcePoolService.getResourcePool(context.getResourcePoolId());
if (resourcePool == null) {
MSException.throwException("Resource Pool is empty");
}
List<TestResource> resourceList = testResourceService.getResourcesByPoolId(resourcePool.getId());
// todo 运行测试 // todo 运行测试
ClientCredential credential = new ClientCredential(); ClientCredential credential = new ClientCredential();
credential.setMasterUrl("https://172.16.10.93:6443"); credential.setMasterUrl("https://172.16.10.93:6443");

View File

@ -41,4 +41,10 @@ public class TestResourceService {
testResource.setUpdateTime(System.currentTimeMillis()); testResource.setUpdateTime(System.currentTimeMillis());
testResourceMapper.updateByPrimaryKeySelective(testResource); testResourceMapper.updateByPrimaryKeySelective(testResource);
} }
public List<TestResource> getResourcesByPoolId(String resourcePoolId) {
TestResourceExample example = new TestResourceExample();
example.createCriteria().andTestResourcePoolIdEqualTo(resourcePoolId);
return testResourceMapper.selectByExampleWithBLOBs(example);
}
} }