11package com .park .utmstack .service .agent_manager ;
22
33import 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 .*;
85import com .park .utmstack .service .grpc .*;
6+ import com .park .utmstack .web .rest .vm .AgentRequestVM ;
97import io .grpc .*;
108import io .grpc .Status ;
119import 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" ;
0 commit comments