Skip to content

Commit

Permalink
[grid] The distributor should handle statuses better
Browse files Browse the repository at this point in the history
  • Loading branch information
shs96c committed Feb 8, 2019
1 parent 9808345 commit ccc65ef
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ protected Distributor(DistributedTracer tracer, HttpClient.Factory httpClientFac
post("/session").using(CreateSession.class),
post("/se/grid/distributor/node").using(AddNode.class),
delete("/se/grid/distributor/node/{nodeId}").using(RemoveNode.class).map("nodeId", UUID::fromString),
get("/se/grid/distributor/status").using(GetDistributorStatus.class),
get("/status").using(StatusHandler.class)
).build();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Licensed to the Software Freedom Conservancy (SFC) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The SFC licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

package org.openqa.selenium.grid.distributor;

import static java.nio.charset.StandardCharsets.UTF_8;

import com.google.common.collect.ImmutableMap;

import org.openqa.selenium.grid.web.CommandHandler;
import org.openqa.selenium.json.Json;
import org.openqa.selenium.remote.http.HttpRequest;
import org.openqa.selenium.remote.http.HttpResponse;

import java.io.IOException;
import java.util.Objects;

class GetDistributorStatus implements CommandHandler {

private final Json json;
private final Distributor distributor;

public GetDistributorStatus(Json json, Distributor distributor) {
this.json = Objects.requireNonNull(json);
this.distributor = Objects.requireNonNull(distributor);
}

@Override
public void execute(HttpRequest req, HttpResponse resp) throws IOException {
DistributorStatus status = distributor.getStatus();

resp.setContent(json.toJson(ImmutableMap.of("value", status)).getBytes(UTF_8));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public void remove(UUID nodeId) {

@Override
public DistributorStatus getStatus() {
HttpRequest request = new HttpRequest(GET, "/status");
HttpRequest request = new HttpRequest(GET, "/se/grid/distributor/status");

HttpResponse response = client.apply(request);

Expand Down

0 comments on commit ccc65ef

Please sign in to comment.