AgentController { @PostConstruct void init() { Map<String, String> env = agentConfiguration.getBuildParameters().getEnvironmentVariables(); String cloudProfileId = env.get("TC_DK_CLD_CLIENT_UUID"); if (cloudProfileId == null) { LOG.info("This agent is not associated with a cloud profile."); return; } LOG.info("Performing initialization for cloud profile " + cloudProfileId + "."); String agentParam = env.get("TC_DK_CLD_AGENT_PARAMS"); if (agentParam == null) { LOG.info("No agent parameters received."); } else { CloudInstanceUserData cloudUserData = CloudInstanceUserData.deserialize(agentParam); if (cloudUserData != null) { final Map<String, String> customParameters = cloudUserData.getCustomAgentConfigurationParameters(); for (Map.Entry<String, String> entry : customParameters.entrySet()) { agentConfiguration.addConfigurationParameter(entry.getKey(), entry.getValue()); } LOG.info("Settings cloud agent custom parameters: " + customParameters); } } LOG.info("Docker cloud agent plugin successfully initialized."); agentConfiguration.addConfigurationParameter(AGENT_RUNTIME_ID, UUID.randomUUID().toString()); } AgentController(BuildAgentConfiguration agentConfiguration);  static final String AGENT_RUNTIME_ID; }
@Test public void unmanagedAgent() { TestBuildAgentConfiguration config = new TestBuildAgentConfiguration(); AgentController ctrl = new AgentController(config); ctrl.init(); assertThat(config.getConfigurationParameters()).isEmpty(); }
@Test public void agentRuntimeId() { TestBuildAgentConfiguration config = new TestBuildAgentConfiguration(); config.getBuildParameters() .withEnv("TC_DK_CLD_CLIENT_UUID", UUID.randomUUID().toString()); AgentController ctrl = new AgentController(config); ctrl.init(); UUID runtimeId1 = UUID.fromString(config.getConfigurationParameters().get(AgentController.AGENT_RUNTIME_ID)); ctrl = new AgentController(config); ctrl.init(); UUID runtimeId2 = UUID.fromString(config.getConfigurationParameters().get(AgentController.AGENT_RUNTIME_ID)); assertThat(runtimeId1).isNotEqualTo(runtimeId2); }
@Test public void agentWithUserData() { TestBuildAgentConfiguration config = new TestBuildAgentConfiguration(); Map<String, String> customParams = new HashMap<>(); customParams.put("KEY1", "VALUE1"); customParams.put("KEY2", "VALUE2"); CloudInstanceUserData userData = new CloudInstanceUserData("", "", "", null, "", "", customParams); config.getBuildParameters() .withEnv("TC_DK_CLD_CLIENT_UUID", UUID.randomUUID().toString()) .withEnv("TC_DK_CLD_AGENT_PARAMS", userData.serialize()); AgentController ctrl = new AgentController(config); ctrl.init(); assertThat(config.getConfigurationParameters()).containsAllEntriesOf(customParams); }
@Test public void agentWithUnparseableUserData() { TestBuildAgentConfiguration config = new TestBuildAgentConfiguration(); config.getBuildParameters() .withEnv("TC_DK_CLD_CLIENT_UUID", UUID.randomUUID().toString()) .withEnv("TC_DK_CLD_AGENT_PARAMS", "NOT A VALID CLOUD INSTANCE USER DATA"); AgentController ctrl = new AgentController(config); ctrl.init(); }