Search in sources :

Example 1 with ConsoleLogAppender

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);
}
Also used : DefaultGoPluginApiResponse(com.thoughtworks.go.plugin.api.response.DefaultGoPluginApiResponse) GoPluginApiResponse(com.thoughtworks.go.plugin.api.response.GoPluginApiResponse) DateTimeFormat(org.joda.time.format.DateTimeFormat) EventStream(com.thoughtworks.gocd.elasticagent.ecs.events.EventStream) Event(com.thoughtworks.gocd.elasticagent.ecs.events.Event) EventFingerprint(com.thoughtworks.gocd.elasticagent.ecs.events.EventFingerprint) LimitExceededException(com.thoughtworks.gocd.elasticagent.ecs.exceptions.LimitExceededException) DateTimeFormatter(org.joda.time.format.DateTimeFormatter) ConsoleLogAppender(com.thoughtworks.gocd.elasticagent.ecs.domain.ConsoleLogAppender) AgentInstances(com.thoughtworks.gocd.elasticagent.ecs.AgentInstances) LocalTime(org.joda.time.LocalTime) PluginRequest(com.thoughtworks.gocd.elasticagent.ecs.PluginRequest) MessageFormat.format(java.text.MessageFormat.format) CreateAgentRequest(com.thoughtworks.gocd.elasticagent.ecs.requests.CreateAgentRequest) RequestExecutor(com.thoughtworks.gocd.elasticagent.ecs.RequestExecutor) ECSTask(com.thoughtworks.gocd.elasticagent.ecs.ECSTask) LOG(com.thoughtworks.gocd.elasticagent.ecs.ECSElasticPlugin.LOG) DefaultGoPluginApiResponse(com.thoughtworks.go.plugin.api.response.DefaultGoPluginApiResponse) LimitExceededException(com.thoughtworks.gocd.elasticagent.ecs.exceptions.LimitExceededException) ConsoleLogAppender(com.thoughtworks.gocd.elasticagent.ecs.domain.ConsoleLogAppender) LimitExceededException(com.thoughtworks.gocd.elasticagent.ecs.exceptions.LimitExceededException)

Aggregations

DefaultGoPluginApiResponse (com.thoughtworks.go.plugin.api.response.DefaultGoPluginApiResponse)1 GoPluginApiResponse (com.thoughtworks.go.plugin.api.response.GoPluginApiResponse)1 AgentInstances (com.thoughtworks.gocd.elasticagent.ecs.AgentInstances)1 LOG (com.thoughtworks.gocd.elasticagent.ecs.ECSElasticPlugin.LOG)1 ECSTask (com.thoughtworks.gocd.elasticagent.ecs.ECSTask)1 PluginRequest (com.thoughtworks.gocd.elasticagent.ecs.PluginRequest)1 RequestExecutor (com.thoughtworks.gocd.elasticagent.ecs.RequestExecutor)1 ConsoleLogAppender (com.thoughtworks.gocd.elasticagent.ecs.domain.ConsoleLogAppender)1 Event (com.thoughtworks.gocd.elasticagent.ecs.events.Event)1 EventFingerprint (com.thoughtworks.gocd.elasticagent.ecs.events.EventFingerprint)1 EventStream (com.thoughtworks.gocd.elasticagent.ecs.events.EventStream)1 LimitExceededException (com.thoughtworks.gocd.elasticagent.ecs.exceptions.LimitExceededException)1 CreateAgentRequest (com.thoughtworks.gocd.elasticagent.ecs.requests.CreateAgentRequest)1 MessageFormat.format (java.text.MessageFormat.format)1 LocalTime (org.joda.time.LocalTime)1 DateTimeFormat (org.joda.time.format.DateTimeFormat)1 DateTimeFormatter (org.joda.time.format.DateTimeFormatter)1