
org.openqa.selenium.grid.data.NodeStatus Maven / Gradle / Ivy
// 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.data;
import static com.google.common.collect.ImmutableList.toImmutableList;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import org.openqa.selenium.Capabilities;
import org.openqa.selenium.ImmutableCapabilities;
import org.openqa.selenium.internal.Require;
import org.openqa.selenium.json.JsonException;
import org.openqa.selenium.remote.SessionId;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.UUID;
public class NodeStatus {
private final UUID nodeId;
private final URI externalUri;
private final int maxSessionCount;
private final Map stereotypes;
private final Set snapshot;
private final String registrationSecret;
public NodeStatus(
UUID nodeId,
URI externalUri,
int maxSessionCount,
Map stereotypes,
Collection snapshot,
String registrationSecret) {
this.nodeId = Require.nonNull("Node id", nodeId);
this.externalUri = Require.nonNull("URI", externalUri);
this.maxSessionCount = Require.positive("Max session count", maxSessionCount);
this.stereotypes = ImmutableMap.copyOf(Require.nonNull("Stereotypes", stereotypes));
this.snapshot = ImmutableSet.copyOf(Require.nonNull("Snapshot", snapshot));
this.registrationSecret = registrationSecret;
}
public boolean hasCapacity() {
return !stereotypes.isEmpty();
}
public boolean hasCapacity(Capabilities caps) {
return stereotypes.getOrDefault(caps, 0) > 0;
}
public UUID getNodeId() {
return nodeId;
}
public URI getUri() {
return externalUri;
}
public int getMaxSessionCount() {
return maxSessionCount;
}
public Map getStereotypes() {
return stereotypes;
}
public Set getCurrentSessions() {
return snapshot;
}
public String getRegistrationSecret() {
return registrationSecret;
}
@Override
public boolean equals(Object o) {
if (!(o instanceof NodeStatus)) {
return false;
}
NodeStatus that = (NodeStatus) o;
return Objects.equals(this.nodeId, that.nodeId) &&
Objects.equals(this.externalUri, that.externalUri) &&
this.maxSessionCount == that.maxSessionCount &&
Objects.equals(this.stereotypes, that.stereotypes) &&
Objects.equals(this.snapshot, that.snapshot) &&
Objects.equals(this.registrationSecret, that.registrationSecret);
}
@Override
public int hashCode() {
return Objects.hash(nodeId, externalUri, maxSessionCount, stereotypes, snapshot);
}
private Map toJson() {
return new ImmutableMap.Builder()
.put("id", nodeId)
.put("uri", externalUri)
.put("maxSessions", maxSessionCount)
.put("stereotypes", asCapacity(stereotypes))
.put("sessions", snapshot)
.put("registrationSecret", Optional.ofNullable(registrationSecret))
.build();
}
private List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy