Skip to content

Commit

Permalink
Public export of Nexus code:
Browse files Browse the repository at this point in the history
  - 8adcf4d525b34c3c6fd00ee3eca9cf14bcac2488 by Sergii Pryhoda <[email protected]>

GitOrigin-RevId: 8adcf4d525b34c3c6fd00ee3eca9cf14bcac2488
  • Loading branch information
userSeprid authored and sonatype-zion committed Feb 27, 2023
1 parent 3aaa42f commit cd0d832
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
*/
package org.sonatype.nexus.internal.node.datastore;

import java.util.Map;

import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
Expand All @@ -24,14 +22,13 @@
import javax.ws.rs.Produces;

import org.sonatype.goodies.common.ComponentSupport;
import org.sonatype.nexus.node.datastore.NodeHeartbeatManager;
import org.sonatype.nexus.common.node.NodeAccess;
import org.sonatype.nexus.node.datastore.NodeIdStore;
import org.sonatype.nexus.rest.Resource;

import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.apache.shiro.authz.annotation.RequiresPermissions;

import static com.google.common.base.Preconditions.checkNotNull;
import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
import static org.sonatype.nexus.rest.APIConstants.V1_API_PREFIX;

Expand All @@ -54,21 +51,21 @@ public class NodeIdApiResource

private final NodeIdStore nodeIdStore;

private final NodeHeartbeatManager nodeHeartbeatManager;
private final NodeAccess nodeAccess;

@Inject
public NodeIdApiResource(final NodeIdStore nodeIdStore,
final NodeHeartbeatManager nodeHeartbeatManager) {
public NodeIdApiResource(final NodeIdStore nodeIdStore, final NodeAccess nodeAccess) {
this.nodeIdStore = nodeIdStore;
this.nodeHeartbeatManager = checkNotNull(nodeHeartbeatManager);
this.nodeAccess = nodeAccess;
}

@Override
@GET
@RequiresAuthentication
@RequiresPermissions("nexus:*")
public Map<String, Map<String, Object>> getNodesInformation() {
return nodeHeartbeatManager.getSystemInformationForNodes();
public NodeInformation getNodeId() {
// we return an object here to maintain an API similar to multi-node
return new NodeInformation(nodeAccess.getId());
}

@Override
Expand All @@ -78,4 +75,12 @@ public Map<String, Map<String, Object>> getNodesInformation() {
public void clear() {
nodeIdStore.clear();
}

public static class NodeInformation {
public final String nodeId;

public NodeInformation(final String nodeId) {
this.nodeId = nodeId;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*/
package org.sonatype.nexus.internal.node.datastore;

import java.util.Map;
import org.sonatype.nexus.internal.node.datastore.NodeIdApiResource.NodeInformation;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
Expand All @@ -27,9 +27,9 @@
@Api(value = "System: Nodes")
public interface NodeIdApiResourceDoc
{
@ApiOperation("Get information about all nodes")
@ApiResponses(value = {@ApiResponse(code = 403, message = "Insufficient permissions to request this data")})
Map<String, Map<String, Object>> getNodesInformation();
@ApiOperation("Get information about this node")
@ApiResponses(value = {@ApiResponse(code = 403, message = "Insufficient permissions to update settings")})
NodeInformation getNodeId();

@ApiOperation("Reset the ID for this node. Takes effect after restart and should only be used when cloning an instance")
@ApiResponses(value = {@ApiResponse(code = 403, message = "Insufficient permissions to update settings")})
Expand Down

0 comments on commit cd0d832

Please sign in to comment.