Skip to content

Commit 1fc3e0d

Browse files
committed
Merge branch 'bugfix/10.5.20/update-agent-hostname' of github.com:utmstack/UTMStack into bugfix/10.5.20/update-agent-hostname
2 parents 12b887e + 802f986 commit 1fc3e0d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+1345
-1606
lines changed

backend/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
<sonar-maven-plugin.version>3.9.0.2155</sonar-maven-plugin.version>
7575
<!-- jhipster-needle-maven-property -->
7676
<io.grpc.version>1.55.1</io.grpc.version>
77-
<protoc.version>3.23.2</protoc.version>
77+
<protoc.version>4.29.3</protoc.version>
7878
<os-maven-plugin.version>1.6.2</os-maven-plugin.version>
7979
<protobuf-maven-plugin.version>0.6.1</protobuf-maven-plugin.version>
8080
<annotation-api.version>1.2</annotation-api.version>
@@ -320,7 +320,7 @@
320320
<dependency>
321321
<groupId>com.google.protobuf</groupId>
322322
<artifactId>protobuf-java</artifactId>
323-
<version>3.23.2</version>
323+
<version>${protoc.version}</version>
324324
</dependency>
325325

326326
<dependency>

backend/src/main/java/com/park/utmstack/service/agent_manager/AgentGrpcService.java

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
package com.park.utmstack.service.agent_manager;
22

33
import com.park.utmstack.security.SecurityUtils;
4-
import com.park.utmstack.service.dto.agent_manager.AgentCommandDTO;
5-
import com.park.utmstack.service.dto.agent_manager.AgentDTO;
6-
import com.park.utmstack.service.dto.agent_manager.ListAgentsCommandsResponseDTO;
7-
import com.park.utmstack.service.dto.agent_manager.ListAgentsResponseDTO;
4+
import com.park.utmstack.service.dto.agent_manager.*;
85
import com.park.utmstack.service.grpc.*;
6+
import com.park.utmstack.web.rest.vm.AgentRequestVM;
97
import io.grpc.*;
108
import io.grpc.Status;
119
import io.grpc.stub.MetadataUtils;
@@ -48,8 +46,8 @@ public ListAgentsResponseDTO mapToListAgentsResponseDTO(ListAgentsResponse respo
4846
ListAgentsResponseDTO dto = new ListAgentsResponseDTO();
4947

5048
List<AgentDTO> agentDTOs = response.getRowsList().stream()
51-
.map(this::protoToDTOAgent)
52-
.collect(Collectors.toList());
49+
.map(this::protoToDTOAgent)
50+
.collect(Collectors.toList());
5351

5452
dto.setAgents(agentDTOs);
5553
dto.setTotal(response.getTotal());
@@ -66,8 +64,8 @@ public ListAgentsCommandsResponseDTO mapToListAgentsCommandsResponseDTO(ListAgen
6664
ListAgentsCommandsResponseDTO dto = new ListAgentsCommandsResponseDTO();
6765

6866
List<AgentCommandDTO> agentCommandDTOs = response.getRowsList().stream()
69-
.map(this::protoToDTOAgentCommand)
70-
.collect(Collectors.toList());
67+
.map(this::protoToDTOAgentCommand)
68+
.collect(Collectors.toList());
7169

7270
dto.setAgentCommands(agentCommandDTOs);
7371
dto.setTotal(response.getTotal());
@@ -87,6 +85,32 @@ public AgentDTO protoToDTOAgent(Agent agent) {
8785
return new AgentDTO(agent);
8886
}
8987

88+
public AuthResponseDTO protoToDTOAuthResponse(AuthResponse auth) {
89+
return new AuthResponseDTO(auth);
90+
}
91+
92+
public AuthResponseDTO updateAgentAttributes(AgentRequestVM agentRequestVM) throws Exception {
93+
final String ctx = CLASSNAME + ".updateAgentAttributes";
94+
try {
95+
AgentRequest req = agentRequestVM.getAgentRequest();
96+
Metadata customHeaders = new Metadata();
97+
customHeaders.put(Metadata.Key.of("key", Metadata.ASCII_STRING_MARSHALLER), agentRequestVM.getAgentKey());
98+
customHeaders.put(Metadata.Key.of("id", Metadata.ASCII_STRING_MARSHALLER), String.valueOf(agentRequestVM.getId()));
99+
100+
Channel intercept = ClientInterceptors.intercept(grpcManagedChannel, MetadataUtils.newAttachHeadersInterceptor(customHeaders));
101+
AgentServiceGrpc.AgentServiceBlockingStub newStub = AgentServiceGrpc.newBlockingStub(intercept);
102+
AuthResponse authResponse = newStub.updateAgent(req);
103+
if (authResponse != null) {
104+
return protoToDTOAuthResponse(authResponse);
105+
} else {
106+
throw new Exception("The agent manager didn't respond to the request, probably is down !!!");
107+
}
108+
} catch (NullPointerException e) {
109+
throw new Exception("The agent manager didn't respond to the request, probably is down !!!");
110+
} catch (Exception e) {
111+
throw new Exception(ctx + ": " + e.getMessage());
112+
}
113+
}
90114

91115
public AgentDTO updateAgentType(AgentTypeUpdate newType) throws Exception {
92116
final String ctx = CLASSNAME + ".updateAgentType";
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.park.utmstack.service.dto.agent_manager;
2+
3+
4+
import com.park.utmstack.service.grpc.AuthResponse;
5+
6+
public class AuthResponseDTO {
7+
private int id;
8+
private String key;
9+
10+
public AuthResponseDTO(AuthResponse authResponse) {
11+
this.id = authResponse.getId();
12+
this.key = authResponse.getKey();
13+
}
14+
15+
public int getId() {
16+
return id;
17+
}
18+
19+
public void setId(int id) {
20+
this.id = id;
21+
}
22+
23+
public String getKey() {
24+
return key;
25+
}
26+
27+
public void setKey(String key) {
28+
this.key = key;
29+
}
30+
}

0 commit comments

Comments
 (0)