use of com.dtstack.taier.pluginapi.pojo.ComponentTestResult in project Taier by DTStack.
the class AbstractRdbsClientTest method testTestConnect.
@Test
public void testTestConnect() throws Exception {
ComponentTestResult result = testRdbsClient.testConnect(null);
Assert.assertFalse(result.getResult());
TestConnFactory connFactory = PowerMockito.mock(TestConnFactory.class);
PowerMockito.doAnswer(new Answer() {
@Override
public String answer(InvocationOnMock invocationOnMock) throws Throwable {
return "test";
}
}).when(connFactory).init(any(Properties.class));
MemberModifier.field(TestRdbsClient.class, "connFactory").set(testRdbsClient, connFactory);
String pluginInfo = "{\"test\": \"test\"}";
ComponentTestResult okResult = testRdbsClient.testConnect(pluginInfo);
Assert.assertTrue(okResult.getResult());
}
use of com.dtstack.taier.pluginapi.pojo.ComponentTestResult in project Taier by DTStack.
the class ConsoleComponentService method testConnect.
/**
* 测试单个组件联通性
*/
public ComponentTestResult testConnect(Integer componentType, String componentConfig, String clusterName, String versionName, Long clusterId, KerberosConfig kerberosConfig, Map<String, String> sftpConfig, Integer storeType, Integer deployType) {
ComponentTestResult componentTestResult = new ComponentTestResult();
try {
if (EComponentType.notCheckComponent.contains(EComponentType.getByCode(componentType))) {
componentTestResult.setResult(true);
return componentTestResult;
}
String typeName = null;
if (EComponentType.HDFS.getTypeCode().equals(componentType)) {
typeName = componentService.buildHdfsTypeName(null, clusterId);
} else {
typeName = convertComponentTypeToClient(clusterName, componentType, versionName, storeType, deployType);
}
JSONObject pluginInfo = componentService.wrapperConfig(componentType, componentConfig, sftpConfig, kerberosConfig, clusterName);
pluginInfo.put(TYPE_NAME_KEY, typeName);
componentTestResult = workerOperator.testConnect(pluginInfo.toJSONString());
if (null == componentTestResult) {
componentTestResult = new ComponentTestResult();
componentTestResult.setResult(false);
componentTestResult.setErrorMsg("测试联通性失败");
return componentTestResult;
}
// 单组件连通性测试回写yarn的队列信息
if (EComponentType.YARN.getTypeCode().equals(componentType) && componentTestResult.getResult() && Objects.nonNull(componentTestResult.getClusterResourceDescription())) {
queueService.updateQueue(clusterId, componentTestResult.getClusterResourceDescription());
}
} catch (Throwable e) {
if (Objects.isNull(componentTestResult)) {
componentTestResult = new ComponentTestResult();
}
componentTestResult.setResult(false);
componentTestResult.setErrorMsg(ExceptionUtil.getErrorMessage(e));
} finally {
if (null != componentTestResult) {
componentTestResult.setComponentTypeCode(componentType);
componentTestResult.setComponentVersion(versionName);
}
}
return componentTestResult;
}
use of com.dtstack.taier.pluginapi.pojo.ComponentTestResult in project Taier by DTStack.
the class ConsoleComponentService method testComponentWithResult.
private ComponentTestResult testComponentWithResult(String clusterName, Cluster cluster, Map sftpMap, Component component) {
ComponentTestResult testResult = new ComponentTestResult();
try {
KerberosConfig kerberosConfig = consoleKerberosMapper.getByComponentType(cluster.getId(), component.getComponentTypeCode(), ComponentVersionUtil.isMultiVersionComponent(component.getComponentTypeCode()) ? StringUtils.isNotBlank(component.getVersionValue()) ? component.getVersionValue() : componentMapper.getDefaultComponentVersionByClusterAndComponentType(cluster.getId(), component.getComponentTypeCode()) : null);
String componentConfig = componentService.getComponentByClusterId(cluster.getId(), component.getComponentTypeCode(), false, String.class, null);
testResult = this.testConnect(component.getComponentTypeCode(), componentConfig, clusterName, component.getVersionName(), component.getClusterId(), kerberosConfig, sftpMap, component.getStoreType(), component.getDeployType());
// 测试联通性
if (EComponentType.YARN.getTypeCode().equals(component.getComponentTypeCode()) && testResult.getResult()) {
if (null != testResult.getClusterResourceDescription()) {
queueService.updateQueue(cluster.getId(), testResult.getClusterResourceDescription());
} else {
testResult.setResult(false);
testResult.setErrorMsg(clusterName + "获取yarn信息为空");
}
}
} catch (Exception e) {
testResult.setResult(false);
testResult.setErrorMsg(ExceptionUtil.getErrorMessage(e));
LOGGER.error("test connect {} error ", component.getId(), e);
} finally {
testResult.setComponentVersion(component.getVersionValue());
testResult.setComponentTypeCode(component.getComponentTypeCode());
}
return testResult;
}
use of com.dtstack.taier.pluginapi.pojo.ComponentTestResult in project Taier by DTStack.
the class ConsoleComponentService method testConnect.
public ComponentTestResult testConnect(String clusterName, Integer componentType, String versionName) {
if (StringUtils.isBlank(clusterName)) {
throw new RdosDefineException(ErrorCode.NAME_FORMAT_ERROR);
}
Cluster cluster = clusterMapper.getByClusterName(clusterName);
if (null == cluster) {
throw new RdosDefineException(ErrorCode.CANT_NOT_FIND_CLUSTER);
}
Component testComponent = componentMapper.getByVersionName(cluster.getId(), componentType, versionName, null);
if (null == testComponent) {
throw new RdosDefineException(ErrorCode.COMPONENT_INVALID);
}
if (EComponentType.notCheckComponent.contains(EComponentType.getByCode(componentType))) {
ComponentTestResult componentTestResult = new ComponentTestResult();
componentTestResult.setComponentTypeCode(componentType);
componentTestResult.setResult(true);
componentTestResult.setComponentVersion(testComponent.getVersionValue());
return componentTestResult;
}
Map sftpMap = componentService.getComponentByClusterId(cluster.getId(), EComponentType.SFTP.getTypeCode(), false, Map.class, null);
return testComponentWithResult(clusterName, cluster, sftpMap, testComponent);
}
use of com.dtstack.taier.pluginapi.pojo.ComponentTestResult in project Taier by DTStack.
the class DtHdfsClient method testConnect.
/**
* 测试联通性 yarn需要返回集群队列信息
* @param pluginInfo
* @return
*/
@Override
public ComponentTestResult testConnect(String pluginInfo) {
ComponentTestResult testResult = new ComponentTestResult();
testResult.setResult(false);
try {
Config allConfig = PublicUtil.jsonStrToObject(pluginInfo, Config.class);
return this.checkHdfsConnect(allConfig);
} catch (Exception e) {
LOG.error("test yarn connect error", e);
testResult.setErrorMsg(ExceptionUtil.getErrorMessage(e));
}
return testResult;
}
Aggregations