Search in sources :

Example 1 with GetTargetsToBuildResponse

use of com.facebook.buck.distributed.thrift.GetTargetsToBuildResponse in project buck by facebook.

the class ThriftCoordinatorServerIntegrationTest method testMakingSimpleRequest.

@Test
public void testMakingSimpleRequest() throws IOException {
    int port = findRandomOpenPortOnAllLocalInterfaces();
    try (ThriftCoordinatorServer server = new ThriftCoordinatorServer(port, BuildTargetsQueue.newEmptyQueue(), STAMPEDE_ID);
        ThriftCoordinatorClient client = new ThriftCoordinatorClient("localhost", port, STAMPEDE_ID)) {
        server.start();
        client.start();
        GetTargetsToBuildResponse response = client.getTargetsToBuild(MINION_ID);
        Assert.assertNotNull(response);
        Assert.assertEquals(GetTargetsToBuildAction.CLOSE_CLIENT, response.getAction());
    }
}
Also used : GetTargetsToBuildResponse(com.facebook.buck.distributed.thrift.GetTargetsToBuildResponse) Test(org.junit.Test)

Example 2 with GetTargetsToBuildResponse

use of com.facebook.buck.distributed.thrift.GetTargetsToBuildResponse in project buck by facebook.

the class ThriftCoordinatorServerIntegrationTest method testThriftServerWithDiamondGraph.

@Test
public void testThriftServerWithDiamondGraph() throws IOException, NoSuchBuildTargetException {
    int port = findRandomOpenPortOnAllLocalInterfaces();
    BuildTargetsQueue diamondQueue = BuildTargetsQueueTest.createDiamondDependencyQueue();
    try (ThriftCoordinatorServer server = new ThriftCoordinatorServer(port, diamondQueue, STAMPEDE_ID);
        ThriftCoordinatorClient client = new ThriftCoordinatorClient("localhost", port, STAMPEDE_ID)) {
        server.start();
        client.start();
        GetTargetsToBuildResponse targetsToBuildResponse = client.getTargetsToBuild(MINION_ID);
        Assert.assertEquals(GetTargetsToBuildAction.BUILD_TARGETS, targetsToBuildResponse.getAction());
        Assert.assertEquals(1, targetsToBuildResponse.getBuildTargetsSize());
        FinishedBuildingResponse finishedBuildingResponse = client.finishedBuilding(MINION_ID, 0);
        Assert.assertTrue(finishedBuildingResponse.continueBuilding);
        targetsToBuildResponse = client.getTargetsToBuild(MINION_ID);
        Assert.assertEquals(GetTargetsToBuildAction.BUILD_TARGETS, targetsToBuildResponse.getAction());
        Assert.assertEquals(2, targetsToBuildResponse.getBuildTargetsSize());
    }
}
Also used : FinishedBuildingResponse(com.facebook.buck.distributed.thrift.FinishedBuildingResponse) GetTargetsToBuildResponse(com.facebook.buck.distributed.thrift.GetTargetsToBuildResponse) Test(org.junit.Test)

Example 3 with GetTargetsToBuildResponse

use of com.facebook.buck.distributed.thrift.GetTargetsToBuildResponse in project buck by facebook.

the class MinionModeRunner method runAndReturnExitCode.

@Override
public int runAndReturnExitCode() throws IOException, InterruptedException {
    try (ThriftCoordinatorClient client = new ThriftCoordinatorClient(coordinatorAddress, coordinatorPort, stampedeId)) {
        client.start();
        final String minionId = generateNewMinionId();
        while (true) {
            GetTargetsToBuildResponse response = client.getTargetsToBuild(minionId);
            switch(response.getAction()) {
                case BUILD_TARGETS:
                    List<String> targetsToBuild = Lists.newArrayList(response.getBuildTargets());
                    LOG.debug(String.format("Minion [%s] is about to build [%d] targets: [%s]", minionId, targetsToBuild.size(), Joiner.on(", ").join(targetsToBuild)));
                    int buildExitCode = builder.buildLocallyAndReturnExitCode(targetsToBuild);
                    LOG.debug(String.format("Minion [%s] finished with exit code [%d].", minionId, buildExitCode));
                    FinishedBuildingResponse finishedResponse = client.finishedBuilding(minionId, buildExitCode);
                    if (!finishedResponse.isContinueBuilding()) {
                        return 0;
                    }
                    break;
                case RETRY_LATER:
                    try {
                        Thread.sleep(RETRY_BACKOFF_MILLIS);
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                    break;
                case CLOSE_CLIENT:
                    return 0;
                case UNKNOWN:
                default:
                    throw new RuntimeException(String.format("CoordinatorClient received unexpected action [%s].", response.getAction()));
            }
        }
    }
}
Also used : FinishedBuildingResponse(com.facebook.buck.distributed.thrift.FinishedBuildingResponse) GetTargetsToBuildResponse(com.facebook.buck.distributed.thrift.GetTargetsToBuildResponse)

Example 4 with GetTargetsToBuildResponse

use of com.facebook.buck.distributed.thrift.GetTargetsToBuildResponse in project buck by facebook.

the class ThriftCoordinatorClient method getTargetsToBuild.

public GetTargetsToBuildResponse getTargetsToBuild(String minionId) throws IOException {
    LOG.debug(String.format("Minion [%s] is requesting targets to build.", minionId));
    Preconditions.checkNotNull(client, "Client was not started.");
    GetTargetsToBuildRequest request = new GetTargetsToBuildRequest().setMinionId(minionId).setStampedeId(stampedeId);
    try {
        GetTargetsToBuildResponse response = client.getTargetsToBuild(request);
        return response;
    } catch (TException e) {
        throw new ThriftException(e);
    }
}
Also used : TException(org.apache.thrift.TException) ThriftException(com.facebook.buck.slb.ThriftException) GetTargetsToBuildRequest(com.facebook.buck.distributed.thrift.GetTargetsToBuildRequest) GetTargetsToBuildResponse(com.facebook.buck.distributed.thrift.GetTargetsToBuildResponse)

Aggregations

GetTargetsToBuildResponse (com.facebook.buck.distributed.thrift.GetTargetsToBuildResponse)4 FinishedBuildingResponse (com.facebook.buck.distributed.thrift.FinishedBuildingResponse)2 Test (org.junit.Test)2 GetTargetsToBuildRequest (com.facebook.buck.distributed.thrift.GetTargetsToBuildRequest)1 ThriftException (com.facebook.buck.slb.ThriftException)1 TException (org.apache.thrift.TException)1