Search in sources :

Example 1 with Message

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

the class ConsoleOutputWebsocketTransmitter method consumeLine.

@Override
public void consumeLine(String line) {
    ConsoleTransmission transmission = new ConsoleTransmission(line, buildId);
    this.webSocketSessionHandler.sendAndWaitForAcknowledgement(new Message(Action.consoleOut, MessageEncoding.encodeData(transmission)));
}
Also used : Message(com.thoughtworks.go.websocket.Message) ConsoleTransmission(com.thoughtworks.go.websocket.ConsoleTransmission)

Example 2 with Message

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

the class JobInstanceStatusMonitorTest method shouldSendCancelMessageIfJobIsCancelled.

@Test
public void shouldSendCancelMessageIfJobIsCancelled() throws Exception {
    AgentConfig agentConfig = AgentMother.remoteAgent();
    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(1));
    Work work = MessageEncoding.decodeWork(agent.messages.get(0).getData());
    assertThat(work, instanceOf(BuildWork.class));
    BuildAssignment assignment = ((BuildWork) work).getAssignment();
    final JobInstance instance = jobInstanceService.buildByIdWithTransitions(assignment.getJobIdentifier().getBuildId());
    transactionTemplate.execute(new TransactionCallbackWithoutResult() {

        @Override
        protected void doInTransactionWithoutResult(TransactionStatus status) {
            jobInstanceService.cancelJob(instance);
        }
    });
    assertThat(agent.messages.size(), is(2));
    assertThat(agent.messages.get(1).getAction(), is(Action.cancelBuild));
}
Also used : AgentConfig(com.thoughtworks.go.config.AgentConfig) Message(com.thoughtworks.go.websocket.Message) JobInstance(com.thoughtworks.go.domain.JobInstance) Work(com.thoughtworks.go.remote.work.Work) BuildWork(com.thoughtworks.go.remote.work.BuildWork) TransactionStatus(org.springframework.transaction.TransactionStatus) BuildAssignment(com.thoughtworks.go.remote.work.BuildAssignment) BuildWork(com.thoughtworks.go.remote.work.BuildWork) TransactionCallbackWithoutResult(org.springframework.transaction.support.TransactionCallbackWithoutResult)

Example 3 with Message

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

the class DefaultBuildStateReporter method reportCompleting.

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

Example 4 with Message

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

the class WebSocketSessionHandlerTest method shouldWaitForAcknowledgementWhileSendingMessages.

@Test
public void shouldWaitForAcknowledgementWhileSendingMessages() throws Exception {
    final Message message = new Message(Action.reportCurrentStatus);
    when(session.getRemote()).thenReturn(new FakeWebSocketEndpoint(new Runnable() {

        @Override
        public void run() {
            handler.acknowledge(new Message(Action.acknowledge, message.getAcknowledgementId()));
        }
    }));
    Thread sendThread = new Thread(new Runnable() {

        @Override
        public void run() {
            handler.sendAndWaitForAcknowledgement(message);
        }
    });
    sendThread.start();
    assertThat(sendThread.isAlive(), is(true));
    sendThread.join();
    assertThat(sendThread.isAlive(), is(false));
}
Also used : Message(com.thoughtworks.go.websocket.Message) Test(org.junit.Test)

Example 5 with Message

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

the class BuildAssignmentServiceIntegrationTest method shouldAssignMatchedJobToAgentsRegisteredInAgentRemoteHandler.

@Test
public void shouldAssignMatchedJobToAgentsRegisteredInAgentRemoteHandler() throws Exception {
    AgentConfig agentConfig = AgentMother.remoteAgent();
    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)));
    AgentInstance agent = agentService.findAgent(agentConfig.getUuid());
    assertFalse(agent.isBuilding());
    buildAssignmentService.onTimer();
    assertThat(this.agent.messages.size(), is(1));
    assertThat(MessageEncoding.decodeWork(this.agent.messages.get(0).getData()), instanceOf(BuildWork.class));
    assertTrue(agent.isBuilding());
}
Also used : Message(com.thoughtworks.go.websocket.Message) BuildWork(com.thoughtworks.go.remote.work.BuildWork)

Aggregations

Message (com.thoughtworks.go.websocket.Message)18 BuildWork (com.thoughtworks.go.remote.work.BuildWork)4 AgentConfig (com.thoughtworks.go.config.AgentConfig)2 JobInstance (com.thoughtworks.go.domain.JobInstance)2 BuildAssignment (com.thoughtworks.go.remote.work.BuildAssignment)2 Username (com.thoughtworks.go.server.domain.Username)2 AgentStub (com.thoughtworks.go.server.websocket.AgentStub)2 ConsoleTransmission (com.thoughtworks.go.websocket.ConsoleTransmission)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 Test (org.junit.Test)1 TransactionStatus (org.springframework.transaction.TransactionStatus)1 TransactionCallbackWithoutResult (org.springframework.transaction.support.TransactionCallbackWithoutResult)1