From 00c53c56b82e5f9a331c086ac50ba3a3ab4b458e Mon Sep 17 00:00:00 2001 From: Nicolas Chaulet Date: Thu, 25 Mar 2021 09:15:59 -0400 Subject: [PATCH] [Fleet] Replace INTERNAL_POLICY_REASSIGN by POLICY_REASSIGN (#94116) --- .../fleet/common/types/models/agent.ts | 3 +-- .../agents/checkin/state_new_actions.ts | 21 +------------------ .../fleet/server/services/agents/reassign.ts | 4 ++-- .../fleet/server/types/models/agent.ts | 2 +- 4 files changed, 5 insertions(+), 25 deletions(-) diff --git a/x-pack/plugins/fleet/common/types/models/agent.ts b/x-pack/plugins/fleet/common/types/models/agent.ts index 35b123b2c64ea..0629a67f0d8d3 100644 --- a/x-pack/plugins/fleet/common/types/models/agent.ts +++ b/x-pack/plugins/fleet/common/types/models/agent.ts @@ -36,8 +36,7 @@ export type AgentActionType = | 'UNENROLL' | 'UPGRADE' | 'SETTINGS' - // INTERNAL* actions are mean to interupt long polling calls these actions will not be distributed to the agent - | 'INTERNAL_POLICY_REASSIGN'; + | 'POLICY_REASSIGN'; export interface NewAgentAction { type: AgentActionType; diff --git a/x-pack/plugins/fleet/server/services/agents/checkin/state_new_actions.ts b/x-pack/plugins/fleet/server/services/agents/checkin/state_new_actions.ts index 7dc19f63a5adb..8810dd6ff1263 100644 --- a/x-pack/plugins/fleet/server/services/agents/checkin/state_new_actions.ts +++ b/x-pack/plugins/fleet/server/services/agents/checkin/state_new_actions.ts @@ -39,7 +39,7 @@ import { getAgentPolicyActionByIds, } from '../actions'; import { appContextService } from '../../app_context'; -import { getAgentById, updateAgent } from '../crud'; +import { updateAgent } from '../crud'; import { toPromiseAbortable, AbortError, createRateLimiter } from './rxjs_utils'; @@ -262,25 +262,6 @@ export function agentCheckinStateNewActionsFactory() { return EMPTY; } - const hasConfigReassign = newActions.some( - (action) => action.type === 'INTERNAL_POLICY_REASSIGN' - ); - if (hasConfigReassign) { - return from(getAgentById(esClient, agent.id)).pipe( - concatMap((refreshedAgent) => { - if (!refreshedAgent.policy_id) { - throw new Error('Agent does not have a policy assigned'); - } - const newAgentPolicy$ = getOrCreateAgentPolicyObservable(refreshedAgent.policy_id); - return newAgentPolicy$; - }), - rateLimiter(), - concatMap((policyAction) => - createAgentActionFromPolicyAction(soClient, esClient, agent, policyAction) - ) - ); - } - return of(newActions); }), filter((data) => data !== undefined), diff --git a/x-pack/plugins/fleet/server/services/agents/reassign.ts b/x-pack/plugins/fleet/server/services/agents/reassign.ts index 5574c42ced053..81b00663d7a8a 100644 --- a/x-pack/plugins/fleet/server/services/agents/reassign.ts +++ b/x-pack/plugins/fleet/server/services/agents/reassign.ts @@ -44,7 +44,7 @@ export async function reassignAgent( await createAgentAction(soClient, esClient, { agent_id: agentId, created_at: new Date().toISOString(), - type: 'INTERNAL_POLICY_REASSIGN', + type: 'POLICY_REASSIGN', }); } @@ -164,7 +164,7 @@ export async function reassignAgents( agentsToUpdate.map((agent) => ({ agent_id: agent.id, created_at: now, - type: 'INTERNAL_POLICY_REASSIGN', + type: 'POLICY_REASSIGN', })) ); diff --git a/x-pack/plugins/fleet/server/types/models/agent.ts b/x-pack/plugins/fleet/server/types/models/agent.ts index b0b28fdb5b2c8..192bb83a88718 100644 --- a/x-pack/plugins/fleet/server/types/models/agent.ts +++ b/x-pack/plugins/fleet/server/types/models/agent.ts @@ -70,7 +70,7 @@ export const NewAgentActionSchema = schema.oneOf([ schema.literal('POLICY_CHANGE'), schema.literal('UNENROLL'), schema.literal('UPGRADE'), - schema.literal('INTERNAL_POLICY_REASSIGN'), + schema.literal('POLICY_REASSIGN'), ]), data: schema.maybe(schema.any()), ack_data: schema.maybe(schema.any()),