feat(nifi): 添加参数上下文功能并优化错误处理
- 新增参数上下文相关模型类- 实现参数上下文创建、更新、删除和查询的API接口 - 优化错误处理,提高异常信息的可读性 - 移除未使用的ProcessorConfig类
This commit is contained in:
parent
5d9fb90fb1
commit
e535d45df3
|
@ -54,11 +54,7 @@ public class NifiClient {
|
||||||
|
|
||||||
public <T> T get(String path, Class<T> responseType) throws IOException {
|
public <T> T get(String path, Class<T> responseType) throws IOException {
|
||||||
return executeRequestWithRetry(() -> {
|
return executeRequestWithRetry(() -> {
|
||||||
Request request = new Request.Builder()
|
Request request = new Request.Builder().url(config.getApiUrl() + path).get().header("Authorization", "Bearer " + accessToken.get()).build();
|
||||||
.url(config.getApiUrl() + path)
|
|
||||||
.get()
|
|
||||||
.header("Authorization", "Bearer " + accessToken.get()).
|
|
||||||
build();
|
|
||||||
return executeRequest(request, responseType);
|
return executeRequest(request, responseType);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -116,10 +112,10 @@ public class NifiClient {
|
||||||
|
|
||||||
private <T> T executeRequest(Request request, Class<T> responseType) throws IOException {
|
private <T> T executeRequest(Request request, Class<T> responseType) throws IOException {
|
||||||
try (Response response = httpClient.newCall(request).execute()) {
|
try (Response response = httpClient.newCall(request).execute()) {
|
||||||
if (!response.isSuccessful()) {
|
|
||||||
throw new IOException("意外的响应码: " + response);
|
|
||||||
}
|
|
||||||
String responseBody = response.body().string();
|
String responseBody = response.body().string();
|
||||||
|
if (!response.isSuccessful()) {
|
||||||
|
throw new IOException("意外的响应码: " + responseBody);
|
||||||
|
}
|
||||||
return objectMapper.readValue(responseBody, responseType);
|
return objectMapper.readValue(responseBody, responseType);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,27 +0,0 @@
|
||||||
package com.hzya.frame.nifi.model;
|
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @Author:liuyang
|
|
||||||
* @Package:com.hzya.frame.nifi.model
|
|
||||||
* @Project:fw-nifi
|
|
||||||
* @name:ProcessorConfig
|
|
||||||
* @Date:2025/5/14 10:01
|
|
||||||
* @Filename:ProcessorConfig
|
|
||||||
*/
|
|
||||||
@Data
|
|
||||||
public class ProcessorConfig {
|
|
||||||
@JsonProperty("name")
|
|
||||||
private String name;
|
|
||||||
|
|
||||||
@JsonProperty("type")
|
|
||||||
private String type;
|
|
||||||
|
|
||||||
@JsonProperty("id")
|
|
||||||
private String id;
|
|
||||||
|
|
||||||
@JsonProperty("state")
|
|
||||||
private String state;
|
|
||||||
}
|
|
|
@ -0,0 +1,17 @@
|
||||||
|
package com.hzya.frame.nifi.model.joinparametercontexts;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Auto-generated: 2025-05-14 18:33:21
|
||||||
|
*
|
||||||
|
* @author bejson.com (i@bejson.com)
|
||||||
|
* @website http://www.bejson.com/java2pojo/
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class Component {
|
||||||
|
private String name;
|
||||||
|
private List<Parameters> parameters;
|
||||||
|
}
|
|
@ -0,0 +1,11 @@
|
||||||
|
package com.hzya.frame.nifi.model.joinparametercontexts;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class Parameter {
|
||||||
|
private String name;
|
||||||
|
private String value;
|
||||||
|
private boolean sensitive;
|
||||||
|
private String description;
|
||||||
|
}
|
|
@ -0,0 +1,9 @@
|
||||||
|
package com.hzya.frame.nifi.model.joinparametercontexts;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class ParameterContextsJoin {
|
||||||
|
private Revision revision;
|
||||||
|
private Component component;
|
||||||
|
}
|
|
@ -0,0 +1,11 @@
|
||||||
|
/**
|
||||||
|
* Copyright 2025 bejson.com
|
||||||
|
*/
|
||||||
|
package com.hzya.frame.nifi.model.joinparametercontexts;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class Parameters {
|
||||||
|
private Parameter parameter;
|
||||||
|
}
|
|
@ -0,0 +1,8 @@
|
||||||
|
package com.hzya.frame.nifi.model.joinparametercontexts;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class Revision {
|
||||||
|
private int version;
|
||||||
|
}
|
|
@ -0,0 +1,14 @@
|
||||||
|
package com.hzya.frame.nifi.model.resultparametercontexts;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class Component {
|
||||||
|
private String name;
|
||||||
|
private List<Parameters> parameters;
|
||||||
|
private List<String> boundProcessGroups;
|
||||||
|
private List<String> inheritedParameterContexts;
|
||||||
|
private String id;
|
||||||
|
}
|
|
@ -0,0 +1,22 @@
|
||||||
|
package com.hzya.frame.nifi.model.resultparametercontexts;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Auto-generated: 2025-05-14 18:44:23
|
||||||
|
*
|
||||||
|
* @author bejson.com (i@bejson.com)
|
||||||
|
* @website http://www.bejson.com/java2pojo/
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class Parameter {
|
||||||
|
private String name;
|
||||||
|
private String description;
|
||||||
|
private String sensitive;
|
||||||
|
private String value;
|
||||||
|
private String provided;
|
||||||
|
private List<String> referencingComponents;
|
||||||
|
private ParameterContext parameterContext;
|
||||||
|
}
|
|
@ -0,0 +1,10 @@
|
||||||
|
package com.hzya.frame.nifi.model.resultparametercontexts;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class ParameterContext {
|
||||||
|
private String id;
|
||||||
|
private Permissions permissions;
|
||||||
|
private Component component;
|
||||||
|
}
|
|
@ -0,0 +1,12 @@
|
||||||
|
package com.hzya.frame.nifi.model.resultparametercontexts;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class ParameterContextsResult {
|
||||||
|
private Revision revision;
|
||||||
|
private String id;
|
||||||
|
private String uri;
|
||||||
|
private Permissions permissions;
|
||||||
|
private Component component;
|
||||||
|
}
|
|
@ -0,0 +1,9 @@
|
||||||
|
package com.hzya.frame.nifi.model.resultparametercontexts;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class Parameters {
|
||||||
|
private boolean canWrite;
|
||||||
|
private Parameter parameter;
|
||||||
|
}
|
|
@ -0,0 +1,9 @@
|
||||||
|
package com.hzya.frame.nifi.model.resultparametercontexts;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class Permissions {
|
||||||
|
private boolean canRead;
|
||||||
|
private boolean canWrite;
|
||||||
|
}
|
|
@ -0,0 +1,9 @@
|
||||||
|
package com.hzya.frame.nifi.model.resultparametercontexts;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class Revision {
|
||||||
|
private int version;
|
||||||
|
private String lastModifier;
|
||||||
|
}
|
|
@ -2,12 +2,16 @@ package com.hzya.frame.nifi.service;
|
||||||
|
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import com.hzya.frame.nifi.client.NifiClient;
|
import com.hzya.frame.nifi.client.NifiClient;
|
||||||
|
import com.hzya.frame.nifi.model.joinparametercontexts.ParameterContextsJoin;
|
||||||
import com.hzya.frame.nifi.model.processgroupid.ProcessGroupsId;
|
import com.hzya.frame.nifi.model.processgroupid.ProcessGroupsId;
|
||||||
import com.hzya.frame.nifi.model.processgrouproot.ProcessGroupsRoot;
|
import com.hzya.frame.nifi.model.processgrouproot.ProcessGroupsRoot;
|
||||||
|
import com.hzya.frame.nifi.model.resultparametercontexts.ParameterContextsResult;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* nifi api 服务类
|
||||||
|
*
|
||||||
* @Author:liuyang
|
* @Author:liuyang
|
||||||
* @Package:com.hzya.frame.nifi.service
|
* @Package:com.hzya.frame.nifi.service
|
||||||
* @Project:fw-nifi
|
* @Project:fw-nifi
|
||||||
|
@ -42,4 +46,30 @@ public class NifiApiService {
|
||||||
return client.get("/flow/process-groups/root", ProcessGroupsRoot.class);
|
return client.get("/flow/process-groups/root", ProcessGroupsRoot.class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建参数上下文
|
||||||
|
*/
|
||||||
|
public ParameterContextsResult createParameterContexts(ParameterContextsJoin parameterContextsJoin) throws Exception {
|
||||||
|
return client.post("/parameter-contexts", parameterContextsJoin, ParameterContextsResult.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新参数上下文
|
||||||
|
*/
|
||||||
|
public ParameterContextsResult updateParameterContexts(ParameterContextsResult parameterContextsJoin) throws Exception {
|
||||||
|
return client.post(StrUtil.format("/parameter-contexts/{contextId}/update-requests", parameterContextsJoin.getId()), parameterContextsJoin, ParameterContextsResult.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除参数上下文
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询参数上下文
|
||||||
|
*/
|
||||||
|
public ParameterContextsResult getParameterContexts(String paramContextsId) throws Exception {
|
||||||
|
return client.get(StrUtil.format("/parameter-contexts/{}", paramContextsId), ParameterContextsResult.class);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue