feat(nifi-client): 添加删除参数上下文功能并优化模型命名- 在 NifiClient 中添加 delete 方法支持 DELETE 请求
- 在 NifiApiService 中实现删除参数上下文的接口 - 优化模型类命名,提高代码可读性 - 更新参数上下文相关 API 调用路径
This commit is contained in:
parent
e535d45df3
commit
9acde1cb1e
|
@ -6,17 +6,14 @@ import okhttp3.*;
|
|||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.SSLSocketFactory;
|
||||
import javax.net.ssl.TrustManager;
|
||||
import javax.net.ssl.X509TrustManager;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.SecureRandom;
|
||||
import java.security.cert.X509Certificate;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
/**
|
||||
* nifi客户端请求处理
|
||||
*
|
||||
* @Author:liuyang
|
||||
* @Package:com.hzya.frame.nifi.client
|
||||
* @Project:fw-nifi
|
||||
|
@ -68,6 +65,27 @@ public class NifiClient {
|
|||
});
|
||||
}
|
||||
|
||||
public <T> T delete(String path, Class<T> responseType) throws IOException {
|
||||
return executeRequestWithRetry(() -> {
|
||||
Request request = new Request.Builder().url(config.getApiUrl() + path).delete().header("Authorization", "Bearer " + accessToken.get()).build();
|
||||
return executeRequest(request, responseType);
|
||||
});
|
||||
}
|
||||
|
||||
public <T> T delete(String path, Map<String, String> queryParams, Class<T> responseType) throws IOException {
|
||||
// 构建 URL 并添加查询参数
|
||||
HttpUrl.Builder urlBuilder = HttpUrl.parse(config.getApiUrl() + path).newBuilder();
|
||||
if (queryParams != null) {
|
||||
queryParams.forEach(urlBuilder::addQueryParameter);
|
||||
}
|
||||
String url = urlBuilder.build().toString();
|
||||
|
||||
return executeRequestWithRetry(() -> {
|
||||
Request request = new Request.Builder().url(url).delete().header("Authorization", "Bearer " + accessToken.get()).build();
|
||||
return executeRequest(request, responseType);
|
||||
});
|
||||
}
|
||||
|
||||
private <T> T executeRequestWithRetry(IOExceptionRunnable<T> runnable) throws IOException {
|
||||
int maxRetries = 2;
|
||||
for (int attempt = 0; attempt < maxRetries; attempt++) {
|
||||
|
@ -78,7 +96,7 @@ public class NifiClient {
|
|||
if (attempt == maxRetries - 1 || !isTokenExpiredError(e)) {
|
||||
throw e;
|
||||
}
|
||||
System.out.println("令牌可能已过期,请刷新并重试。。。");
|
||||
System.out.println("令牌可能已过期,请刷新并重试...");
|
||||
try {
|
||||
accessToken.set(getAccessToken());
|
||||
tokenIssueTime = System.currentTimeMillis();
|
||||
|
|
|
@ -11,7 +11,7 @@ import java.util.List;
|
|||
* @website http://www.bejson.com/java2pojo/
|
||||
*/
|
||||
@Data
|
||||
public class Component {
|
||||
public class Component3 {
|
||||
private String name;
|
||||
private List<Parameters> parameters;
|
||||
private List<Parameters2> parameters;
|
||||
}
|
|
@ -3,7 +3,7 @@ package com.hzya.frame.nifi.model.joinparametercontexts;
|
|||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class Parameter {
|
||||
public class Parameter2 {
|
||||
private String name;
|
||||
private String value;
|
||||
private boolean sensitive;
|
|
@ -5,5 +5,5 @@ import lombok.Data;
|
|||
@Data
|
||||
public class ParameterContextsJoin {
|
||||
private Revision revision;
|
||||
private Component component;
|
||||
private Component3 component;
|
||||
}
|
|
@ -6,6 +6,6 @@ package com.hzya.frame.nifi.model.joinparametercontexts;
|
|||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class Parameters {
|
||||
private Parameter parameter;
|
||||
public class Parameters2 {
|
||||
private Parameter2 parameter;
|
||||
}
|
|
@ -3,7 +3,7 @@ package com.hzya.frame.nifi.model.processgrouproot;
|
|||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class Component {
|
||||
public class Component4 {
|
||||
private String id;
|
||||
private String versionedComponentId;
|
||||
private String parentGroupId;
|
|
@ -3,7 +3,7 @@ package com.hzya.frame.nifi.model.processgrouproot;
|
|||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class Component2 {
|
||||
public class Component5 {
|
||||
private String id;
|
||||
private String name;
|
||||
}
|
|
@ -14,5 +14,5 @@ import lombok.Data;
|
|||
public class ParameterContext {
|
||||
private String id;
|
||||
private Permissions permissions;
|
||||
private Component2 component;
|
||||
private Component5 component;
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ public class ProcessGroups {
|
|||
private Position position;
|
||||
private Permissions permissions;
|
||||
private List<Bulletins> bulletins;
|
||||
private Component component;
|
||||
private Component4 component;
|
||||
private Status status;
|
||||
private String runningCount;
|
||||
private String stoppedCount;
|
||||
|
|
|
@ -5,7 +5,7 @@ import lombok.Data;
|
|||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class Component {
|
||||
public class Component6 {
|
||||
private String name;
|
||||
private List<Parameters> parameters;
|
||||
private List<String> boundProcessGroups;
|
|
@ -6,5 +6,5 @@ import lombok.Data;
|
|||
public class ParameterContext {
|
||||
private String id;
|
||||
private Permissions permissions;
|
||||
private Component component;
|
||||
private Component6 component;
|
||||
}
|
|
@ -8,5 +8,5 @@ public class ParameterContextsResult {
|
|||
private String id;
|
||||
private String uri;
|
||||
private Permissions permissions;
|
||||
private Component component;
|
||||
private Component6 component;
|
||||
}
|
|
@ -4,6 +4,6 @@ import lombok.Data;
|
|||
|
||||
@Data
|
||||
public class Parameters {
|
||||
private boolean canWrite;
|
||||
private String canWrite;
|
||||
private Parameter parameter;
|
||||
}
|
|
@ -9,6 +9,8 @@ import com.hzya.frame.nifi.model.resultparametercontexts.ParameterContextsResult
|
|||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* nifi api 服务类
|
||||
*
|
||||
|
@ -58,13 +60,9 @@ public class NifiApiService {
|
|||
* 更新参数上下文
|
||||
*/
|
||||
public ParameterContextsResult updateParameterContexts(ParameterContextsResult parameterContextsJoin) throws Exception {
|
||||
return client.post(StrUtil.format("/parameter-contexts/{contextId}/update-requests", parameterContextsJoin.getId()), parameterContextsJoin, ParameterContextsResult.class);
|
||||
return client.post(StrUtil.format("/parameter-contexts/{}/update-requests", parameterContextsJoin.getId()), parameterContextsJoin, ParameterContextsResult.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除参数上下文
|
||||
*/
|
||||
|
||||
/**
|
||||
* 查询参数上下文
|
||||
*/
|
||||
|
@ -72,4 +70,17 @@ public class NifiApiService {
|
|||
return client.get(StrUtil.format("/parameter-contexts/{}", paramContextsId), ParameterContextsResult.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除参数上下文
|
||||
*/
|
||||
public void deleteParameterContexts(String paramContextsId) throws Exception {
|
||||
client.delete(StrUtil.format("/parameter-contexts/{}", paramContextsId), ParameterContextsResult.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除参数上下文,待query参数
|
||||
*/
|
||||
public ParameterContextsResult deleteParameterContexts(String id, Map<String, String> queryParams) throws Exception {
|
||||
return client.delete(StrUtil.format("/parameter-contexts/{}", id), queryParams, ParameterContextsResult.class);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue