Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
162 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
rest/src/main/java/io/atomix/rest/impl/AtomixResource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,44 @@ | |||
/* | |||
* Copyright 2017-present Open Networking Foundation | |||
* | |||
* Licensed 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 io.atomix.rest.impl; | |||
|
|||
import io.atomix.cluster.ClusterService; | |||
|
|||
import javax.ws.rs.Path; | |||
|
|||
/** | |||
* Atomix resource. | |||
*/ | |||
@Path("/") | |||
public class AtomixResource { | |||
private final ClusterService clusterService; | |||
private final PrimitiveCache primitiveCache; | |||
|
|||
public AtomixResource(ClusterService clusterService, PrimitiveCache primitiveCache) { | |||
this.clusterService = clusterService; | |||
this.primitiveCache = primitiveCache; | |||
} | |||
|
|||
@Path("/cluster") | |||
public ClusterResource getCluster() { | |||
return new ClusterResource(clusterService); | |||
} | |||
|
|||
@Path("/primitives") | |||
public PrimitivesResource getPrimitives() { | |||
return new PrimitivesResource(primitiveCache); | |||
} | |||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 96 additions & 0 deletions
96
rest/src/main/java/io/atomix/rest/impl/ClusterResource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,96 @@ | |||
/* | |||
* Copyright 2017-present Open Networking Foundation | |||
* | |||
* Licensed 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 io.atomix.rest.impl; | |||
|
|||
import io.atomix.cluster.ClusterService; | |||
import io.atomix.cluster.Node; | |||
import io.atomix.cluster.NodeId; | |||
|
|||
import javax.ws.rs.GET; | |||
import javax.ws.rs.Path; | |||
import javax.ws.rs.PathParam; | |||
import javax.ws.rs.Produces; | |||
import javax.ws.rs.core.MediaType; | |||
import javax.ws.rs.core.Response; | |||
import javax.ws.rs.core.Response.Status; | |||
import java.util.stream.Collectors; | |||
|
|||
/** | |||
* Cluster resource. | |||
*/ | |||
public class ClusterResource extends AbstractRestResource { | |||
private final ClusterService clusterService; | |||
|
|||
public ClusterResource(ClusterService clusterService) { | |||
this.clusterService = clusterService; | |||
} | |||
|
|||
@GET | |||
@Path("/node") | |||
@Produces(MediaType.APPLICATION_JSON) | |||
public Response getNode() { | |||
return Response.ok(new NodeInfo(clusterService.localNode())).build(); | |||
} | |||
|
|||
@GET | |||
@Path("/nodes") | |||
@Produces(MediaType.APPLICATION_JSON) | |||
public Response getNodes() { | |||
return Response.ok(clusterService.nodes().stream().map(NodeInfo::new).collect(Collectors.toList())).build(); | |||
} | |||
|
|||
@GET | |||
@Path("/nodes/{node}") | |||
@Produces(MediaType.APPLICATION_JSON) | |||
public Response getNodeInfo(@PathParam("node") String nodeId) { | |||
Node node = clusterService.node(NodeId.from(nodeId)); | |||
if (node == null) { | |||
return Response.status(Status.NOT_FOUND).build(); | |||
} | |||
return Response.ok(new NodeInfo(node)).build(); | |||
} | |||
|
|||
/** | |||
* Node information. | |||
*/ | |||
static class NodeInfo { | |||
private final Node node; | |||
|
|||
NodeInfo(Node node) { | |||
this.node = node; | |||
} | |||
|
|||
public String getId() { | |||
return node.id().id(); | |||
} | |||
|
|||
public String getHost() { | |||
return node.endpoint().host().getHostAddress(); | |||
} | |||
|
|||
public int getPort() { | |||
return node.endpoint().port(); | |||
} | |||
|
|||
public Node.Type getType() { | |||
return node.type(); | |||
} | |||
|
|||
public Node.State getStatus() { | |||
return node.state(); | |||
} | |||
} | |||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters