Search in sources :

Example 11 with Message

use of com.thoughtworks.go.websocket.Message in project gocd by gocd.

the class DefaultBuildStateReporter method reportCompleted.

@Override
public void reportCompleted(String buildId, JobResult buildResult) {
    Report report = new Report(agentRuntimeInfo, buildId, null, buildResult);
    webSocketSessionHandler.sendAndWaitForAcknowledgement(new Message(Action.reportCompleted, MessageEncoding.encodeData(report)));
}
Also used : Message(com.thoughtworks.go.websocket.Message) Report(com.thoughtworks.go.websocket.Report)

Example 12 with Message

use of com.thoughtworks.go.websocket.Message in project gocd by gocd.

the class BuildAssignmentService method matchingJobForRegisteredAgents.

private void matchingJobForRegisteredAgents() {
    Map<String, Agent> agents = agentRemoteHandler.connectedAgents();
    if (agents.isEmpty()) {
        return;
    }
    Long start = System.currentTimeMillis();
    for (Map.Entry<String, Agent> entry : agents.entrySet()) {
        String agentUUId = entry.getKey();
        Agent agent = entry.getValue();
        AgentInstance agentInstance = agentService.findAgentAndRefreshStatus(agentUUId);
        if (!agentInstance.isRegistered()) {
            agent.send(new Message(Action.reregister));
            continue;
        }
        if (agentInstance.isDisabled() || !agentInstance.isIdle()) {
            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug("Ignore agent [{}] that is {}", agentInstance.getAgentIdentifier().toString(), agentInstance.getStatus());
            }
            continue;
        }
        Work work = assignWorkToAgent(agentInstance);
        if (work != NO_WORK) {
            if (agentInstance.getSupportsBuildCommandProtocol()) {
                BuildSettings buildSettings = createBuildSettings(((BuildWork) work).getAssignment());
                agent.send(new Message(Action.build, MessageEncoding.encodeData(buildSettings)));
            } else {
                agent.send(new Message(Action.assignWork, MessageEncoding.encodeWork(work)));
            }
        }
    }
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("Matching {} agents with {} jobs took: {}ms", agents.size(), jobPlans.size(), System.currentTimeMillis() - start);
    }
}
Also used : Agent(com.thoughtworks.go.server.websocket.Agent) Message(com.thoughtworks.go.websocket.Message) Map(java.util.Map)

Example 13 with Message

use of com.thoughtworks.go.websocket.Message in project gocd by gocd.

the class BuildAssignmentServiceIntegrationTest method shouldNotAssignDeniedAgentWorkToAgentsRegisteredInAgentRemoteHandler.

@Test
public void shouldNotAssignDeniedAgentWorkToAgentsRegisteredInAgentRemoteHandler() throws Exception {
    AgentConfig agentConfig = AgentMother.remoteAgent();
    agentConfig.disable();
    configHelper.addAgent(agentConfig);
    fixture.createPipelineWithFirstStageScheduled();
    AgentRuntimeInfo info = AgentRuntimeInfo.fromServer(agentConfig, true, "location", 1000000l, "OS", false);
    info.setCookie("cookie");
    agentRemoteHandler.process(agent, new Message(Action.ping, MessageEncoding.encodeData(info)));
    buildAssignmentService.onTimer();
    assertThat(agent.messages.size(), is(0));
}
Also used : Message(com.thoughtworks.go.websocket.Message)

Example 14 with Message

use of com.thoughtworks.go.websocket.Message in project gocd by gocd.

the class BuildAssignmentServiceIntegrationTest method shouldOnlyAssignWorkToIdleAgentsRegisteredInAgentRemoteHandler.

@Test
public void shouldOnlyAssignWorkToIdleAgentsRegisteredInAgentRemoteHandler() throws Exception {
    AgentConfig agentConfig = AgentMother.remoteAgent();
    configHelper.addAgent(agentConfig);
    fixture.createPipelineWithFirstStageScheduled();
    AgentRuntimeInfo info = AgentRuntimeInfo.fromServer(agentConfig, true, "location", 1000000l, "OS", false);
    info.setCookie("cookie");
    AgentStatus[] statuses = new AgentStatus[] { AgentStatus.Building, AgentStatus.Pending, AgentStatus.Disabled, AgentStatus.Disabled, AgentStatus.LostContact, AgentStatus.Missing };
    for (AgentStatus status : statuses) {
        info.setStatus(status);
        agent = new AgentStub();
        agentRemoteHandler.process(agent, new Message(Action.ping, MessageEncoding.encodeData(info)));
        buildAssignmentService.onTimer();
        assertThat("Should not assign work when agent status is " + status, agent.messages.size(), is(0));
    }
}
Also used : Message(com.thoughtworks.go.websocket.Message) AgentStub(com.thoughtworks.go.server.websocket.AgentStub)

Example 15 with Message

use of com.thoughtworks.go.websocket.Message in project gocd by gocd.

the class BuildAssignmentServiceIntegrationTest method shouldNotAssignNoWorkToAgentsRegisteredInAgentRemoteHandler.

@Test
public void shouldNotAssignNoWorkToAgentsRegisteredInAgentRemoteHandler() throws Exception {
    AgentConfig agentConfig = AgentMother.remoteAgent();
    configHelper.addAgent(agentConfig);
    fixture.createdPipelineWithAllStagesPassed();
    AgentRuntimeInfo info = AgentRuntimeInfo.fromServer(agentConfig, true, "location", 1000000l, "OS", false);
    info.setCookie("cookie");
    agentRemoteHandler.process(agent, new Message(Action.ping, MessageEncoding.encodeData(info)));
    buildAssignmentService.onTimer();
    assertThat(agent.messages.size(), is(0));
}
Also used : Message(com.thoughtworks.go.websocket.Message)

Aggregations

Message (com.thoughtworks.go.websocket.Message)17 BuildWork (com.thoughtworks.go.remote.work.BuildWork)4 AgentConfig (com.thoughtworks.go.config.AgentConfig)2 JobInstance (com.thoughtworks.go.domain.JobInstance)2 JobPlan (com.thoughtworks.go.domain.JobPlan)2 Username (com.thoughtworks.go.server.domain.Username)2 AgentStub (com.thoughtworks.go.server.websocket.AgentStub)2 Report (com.thoughtworks.go.websocket.Report)2 AgentIdentifier (com.thoughtworks.go.remote.AgentIdentifier)1 Work (com.thoughtworks.go.remote.work.Work)1 Agent (com.thoughtworks.go.server.websocket.Agent)1 ConsoleTransmission (com.thoughtworks.go.websocket.ConsoleTransmission)1 Map (java.util.Map)1 Test (org.junit.Test)1 TransactionStatus (org.springframework.transaction.TransactionStatus)1 TransactionCallbackWithoutResult (org.springframework.transaction.support.TransactionCallbackWithoutResult)1