use of com.thoughtworks.gocd.elasticagent.ecs.domain.ConsoleLogAppender in project gocd-ecs-elastic-agent by gocd.
the class CreateAgentRequestExecutor method execute.
@Override
public GoPluginApiResponse execute() {
ConsoleLogAppender consoleLogAppender = text -> {
final String message = String.format("%s %s\n", LocalTime.now().toString(MESSAGE_PREFIX_FORMATTER), text);
pluginRequest.appendToConsoleLog(request.getJobIdentifier(), message);
};
try {
consoleLogAppender.accept(String.format("Received a request to create an agent for the job: [%s]", request.getJobIdentifier().getRepresentation()));
LOG.info(format("[create-agent] Creating agent with profile {0}", request.elasticProfile().toJson()));
agentInstances.create(request, request.clusterProfileProperties(), consoleLogAppender);
LOG.info(format("[create-agent] Done creating agent for profile : {0}", request.elasticProfile().toJson()));
eventStream.remove(EventFingerprint.forElasticProfile(request.elasticProfile()));
eventStream.remove(EventFingerprint.forCreateEC2Instance());
} catch (LimitExceededException e) {
eventStream.update(Event.warningEvent(EventFingerprint.forCreateEC2Instance(), e.getMessage(), null));
LOG.warn(e.getMessage(), e);
} catch (Exception e) {
eventStream.update(Event.errorEvent(EventFingerprint.forElasticProfile(request.elasticProfile()), format("Error creating agent for profile: {0}", request.elasticProfile().toJson()), e.getMessage()));
LOG.error(format("[create-agent] Failed to create an agent for profile : {0}", request.elasticProfile().toJson()), e);
}
return new DefaultGoPluginApiResponse(200);
}
Aggregations