|
30 | 30 | import java.util.Vector;
|
31 | 31 | import java.util.concurrent.CountDownLatch;
|
32 | 32 |
|
33 |
| -import com.amazonaws.regions.Regions; |
34 | 33 | import com.google.common.collect.ImmutableMap;
|
35 | 34 | import com.intuit.tank.http.TankHttpClient;
|
36 | 35 | import org.apache.commons.io.FileUtils;
|
|
43 | 42 | import org.apache.logging.log4j.core.LoggerContext;
|
44 | 43 | import org.apache.logging.log4j.core.config.Configuration;
|
45 | 44 | import org.apache.logging.log4j.core.config.LoggerConfig;
|
| 45 | +import org.apache.logging.log4j.message.ObjectMessage; |
46 | 46 |
|
47 | 47 | import com.intuit.tank.AgentServiceClient;
|
48 | 48 | import com.intuit.tank.api.model.v1.cloud.CloudVmStatus;
|
|
67 | 67 | import com.intuit.tank.vm.api.enumerated.WatsAgentCommand;
|
68 | 68 | import com.intuit.tank.vm.common.TankConstants;
|
69 | 69 | import com.intuit.tank.vm.settings.TankConfig;
|
70 |
| -import org.apache.logging.log4j.message.ObjectMessage; |
| 70 | +import software.amazon.awssdk.regions.internal.util.EC2MetadataUtils; |
71 | 71 |
|
72 | 72 | public class APITestHarness {
|
73 | 73 | private static Logger LOG = LogManager.getLogger(APITestHarness.class);
|
@@ -141,12 +141,13 @@ public static void main(String[] args) {
|
141 | 141 | }
|
142 | 142 |
|
143 | 143 | HostInfo hostInfo = new HostInfo();
|
144 |
| - ThreadContext.put("jobId", getInstance().getAgentRunData().getJobId()); |
145 |
| - ThreadContext.put("projectName", getInstance().getAgentRunData().getProjectName()); |
146 |
| - ThreadContext.put("instanceId", getInstance().getAgentRunData().getInstanceId()); |
| 144 | + ThreadContext.put("jobId", AmazonUtil.getJobId()); |
| 145 | + ThreadContext.put("projectName", AmazonUtil.getProjectName()); |
| 146 | + ThreadContext.put("instanceId", AmazonUtil.getInstanceId()); |
147 | 147 | ThreadContext.put("publicIp", hostInfo.getPublicIp());
|
148 |
| - ThreadContext.put("region", AmazonUtil.getVMRegion().getRegion()); |
| 148 | + ThreadContext.put("location", AmazonUtil.getZone()); |
149 | 149 | ThreadContext.put("httpHost", AmazonUtil.getControllerBaseUrl());
|
| 150 | + ThreadContext.put("loggingProfile", AmazonUtil.getLoggingProfile().getDisplayName()); |
150 | 151 |
|
151 | 152 | getInstance().initializeFromArgs(args);
|
152 | 153 | }
|
@@ -302,23 +303,12 @@ private void startHttp(String baseUrl) {
|
302 | 303 | if (capacity < 0) {
|
303 | 304 | capacity = AmazonUtil.getCapacity();
|
304 | 305 | }
|
305 |
| - VMRegion region = VMRegion.STANDALONE; |
306 |
| - if (AmazonUtil.isInAmazon()) { |
307 |
| - region = AmazonUtil.getVMRegion(); |
308 |
| - } |
309 | 306 | agentRunData.setJobId(AmazonUtil.getJobId());
|
310 | 307 | agentRunData.setStopBehavior(AmazonUtil.getStopBehavior());
|
311 |
| - |
312 | 308 | LogUtil.getLogEvent().setJobId(agentRunData.getJobId());
|
313 |
| - ThreadContext.put("jobId", agentRunData.getJobId()); |
314 |
| - ThreadContext.put("projectName", agentRunData.getProjectName()); |
315 |
| - ThreadContext.put("instanceId", agentRunData.getInstanceId()); |
316 |
| - ThreadContext.put("publicIp", hostInfo.getPublicIp()); |
317 |
| - ThreadContext.put("region", Regions.getCurrentRegion().getName()); |
318 |
| - ThreadContext.put("httpHost", baseUrl); |
319 |
| - LOG.info(new ObjectMessage(ImmutableMap.of("Message", "Active Profile" + agentRunData.getActiveProfile().getDisplayName()))); |
| 309 | + |
320 | 310 | AgentData data = new AgentData(agentRunData.getJobId(), instanceId, instanceUrl, capacity,
|
321 |
| - region, AmazonUtil.getZone()); |
| 311 | + AmazonUtil.getVMRegion(), AmazonUtil.getZone()); |
322 | 312 | try {
|
323 | 313 | AgentTestStartData startData = null;
|
324 | 314 | int count = 0;
|
@@ -614,12 +604,8 @@ public CloudVmStatus getInitialStatus() {
|
614 | 604 | VMRegion region = VMRegion.STANDALONE;
|
615 | 605 | String secGroups = "unknown";
|
616 | 606 | if (AmazonUtil.isInAmazon()) {
|
617 |
| - try { |
618 |
| - region = AmazonUtil.getVMRegion(); |
619 |
| - secGroups = AmazonUtil.getMetaData(CloudMetaDataType.security_groups); |
620 |
| - } catch (IOException e) { |
621 |
| - LOG.warn(new ObjectMessage(ImmutableMap.of("Message", "Error gettting region. using Custom..."))); |
622 |
| - } |
| 607 | + region = AmazonUtil.getVMRegion(); |
| 608 | + secGroups = EC2MetadataUtils.getSecurityGroups().get(0); |
623 | 609 | }
|
624 | 610 | status = new CloudVmStatus(instanceId, agentRunData.getJobId(), secGroups, JobStatus.Unknown,
|
625 | 611 | VMImageType.AGENT, region, VMStatus.running,
|
@@ -713,9 +699,9 @@ public void checkAgentThreads() {
|
713 | 699 | threadGroup.enumerate(threads);
|
714 | 700 | int activeThreads = (int) Arrays.stream(threads).filter(Objects::nonNull).filter(
|
715 | 701 | t -> t.getState() == Thread.State.TIMED_WAITING || t.getState() == Thread.State.WAITING).count();
|
716 |
| - LOG.info(new ObjectMessage(ImmutableMap.of("Message", "Have " + activeThreads + " of " + activeCount |
| 702 | + LOG.info(LogUtil.getLogMessage("Have " + activeThreads + " of " + activeCount |
717 | 703 | + " active Threads in thread group "
|
718 |
| - + threadGroup.getName()))); |
| 704 | + + threadGroup.getName())); |
719 | 705 | }
|
720 | 706 | if (hasMetSimulationTime()) { // && doneSignal.getCount() != 0) {
|
721 | 707 | LOG.info(LogUtil.getLogMessage("Max simulation time has been met and there are "
|
|
0 commit comments