feat: pcap 增加 unparse2session 接口
This commit is contained in:
@@ -157,4 +157,13 @@ public class PcapController {
|
||||
}
|
||||
return R.ok(result);
|
||||
}
|
||||
|
||||
|
||||
@PutMapping("/unparse2session")
|
||||
public R unparse2session(String[] ids) {
|
||||
T.VerifyUtil.is(ids).notEmpty();
|
||||
|
||||
pcapService.unparse2session(ids);
|
||||
return R.ok();
|
||||
}
|
||||
}
|
||||
@@ -21,4 +21,5 @@ public interface IPcapService extends IService<PcapEntity>{
|
||||
|
||||
void parse2session(String... ids);
|
||||
|
||||
void unparse2session(String[] ids);
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import net.geedge.asw.common.config.SpringContextUtils;
|
||||
import net.geedge.asw.common.util.ASWException;
|
||||
import net.geedge.asw.common.util.RCode;
|
||||
import net.geedge.asw.common.util.T;
|
||||
@@ -29,6 +30,9 @@ import net.geedge.asw.module.workbook.util.WorkbookConstant;
|
||||
import net.geedge.asw.module.workspace.entity.WorkspaceEntity;
|
||||
import net.geedge.asw.module.workspace.service.IWorkspaceService;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.opensearch.client.opensearch.OpenSearchClient;
|
||||
import org.opensearch.client.opensearch.indices.DeleteIndexRequest;
|
||||
import org.opensearch.client.opensearch.indices.ExistsRequest;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.core.io.Resource;
|
||||
@@ -225,6 +229,42 @@ public class PcapServiceImpl extends ServiceImpl<PcapDao, PcapEntity> implements
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unparse2session(String[] ids) {
|
||||
OpenSearchClient openSearchClient = (OpenSearchClient) SpringContextUtils.getBean("openSearchClient");
|
||||
|
||||
for (String id : ids) {
|
||||
PcapEntity pcapEntity = this.getById(id);
|
||||
if (T.ObjectUtil.isNotNull(pcapEntity)) {
|
||||
WorkspaceEntity workspace = workspaceService.getById(pcapEntity.getWorkspaceId());
|
||||
pcapEntity.setWorkspace(workspace);
|
||||
String pcapPath = pcapEntity.getPath();
|
||||
String md5Hex = T.DigestUtil.md5Hex(T.FileUtil.file(pcapPath));
|
||||
|
||||
String workspaceName = pcapEntity.getWorkspace().getName();
|
||||
String indexName = String.format("workspace-%s-%s", workspaceName, md5Hex);
|
||||
|
||||
try {
|
||||
// check if index exists
|
||||
boolean indexExists = openSearchClient.indices()
|
||||
.exists(new ExistsRequest.Builder().index(indexName).build())
|
||||
.value();
|
||||
|
||||
// if index exists, delete
|
||||
if (indexExists) {
|
||||
openSearchClient.indices().delete(new DeleteIndexRequest.Builder().index(indexName).build());
|
||||
log.debug("delete openSearch index: {}", indexName);
|
||||
}
|
||||
}catch (Exception e){
|
||||
log.error("delete openSearch index error index: {}", indexName);
|
||||
throw new RuntimeException("delete openSearch index error ", e);
|
||||
}
|
||||
pcapEntity.setStatus(RunnerConstant.PcapStatus.UPLOADED.getValue());
|
||||
this.updateById(pcapEntity);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* calculate Parse Thread Timeout
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user