Skip to content

Commit

Permalink
GEODE-7131: update spring annotation (apache#4171)
Browse files Browse the repository at this point in the history
Co-authored-by: Joris Melchior <[email protected]>
  • Loading branch information
jinmeiliao and jmelchio authored Oct 17, 2019
1 parent ed8bfe2 commit a905e70
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 74 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@

import org.apache.geode.management.api.ClusterManagementService;
import org.apache.geode.management.client.ClusterManagementServiceBuilder;
import org.apache.geode.management.configuration.Region;
import org.apache.geode.test.junit.rules.LocatorStarterRule;

public class ClusterManagementRestLoggingTest {
Expand All @@ -43,8 +42,6 @@ public static void beforeClass() throws Exception {
@Test
public void ping() throws Exception {
assertThat(cms.isConnected()).isTrue();
Region region = new Region();
cms.list(region);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
import org.apache.geode.management.internal.api.LocatorClusterManagementService;

public class AbstractManagementController implements ServletContextAware {

protected static final String MANAGEMENT_API_VERSION = "/experimental";
protected SecurityService securityService;
protected LocatorClusterManagementService clusterManagementService;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,20 @@
package org.apache.geode.management.internal.rest.controllers;

import static org.apache.geode.management.configuration.GatewayReceiver.GATEWAY_RECEIVERS_ENDPOINTS;
import static org.apache.geode.management.internal.rest.controllers.AbstractManagementController.MANAGEMENT_API_VERSION;
import static org.apache.geode.management.configuration.Links.URI_VERSION;

import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import org.apache.geode.management.api.ClusterManagementGetResult;
import org.apache.geode.management.api.ClusterManagementListResult;
Expand All @@ -38,13 +38,12 @@
import org.apache.geode.management.runtime.GatewayReceiverInfo;


@Controller("gatewayManagement")
@RequestMapping(MANAGEMENT_API_VERSION)
@RestController("gatewayManagement")
@RequestMapping(URI_VERSION)
public class GatewayManagementController extends AbstractManagementController {
@ApiOperation(value = "list gateway-receivers")
@PreAuthorize("@securityService.authorize('CLUSTER', 'READ')")
@RequestMapping(method = RequestMethod.GET, value = GATEWAY_RECEIVERS_ENDPOINTS)
@ResponseBody
@GetMapping(GATEWAY_RECEIVERS_ENDPOINTS)
public ClusterManagementListResult<GatewayReceiver, GatewayReceiverInfo> listGatewayReceivers(
@RequestParam(required = false) String group) {
GatewayReceiver filter = new GatewayReceiver();
Expand All @@ -56,8 +55,7 @@ public ClusterManagementListResult<GatewayReceiver, GatewayReceiverInfo> listGat

@ApiOperation(value = "get gateway-receiver")
@PreAuthorize("@securityService.authorize('CLUSTER', 'READ')")
@RequestMapping(method = RequestMethod.GET, value = GATEWAY_RECEIVERS_ENDPOINTS + "/{id}")
@ResponseBody
@GetMapping(GATEWAY_RECEIVERS_ENDPOINTS + "/{id}")
public ClusterManagementGetResult<GatewayReceiver, GatewayReceiverInfo> getGatewayReceiver(
@PathVariable(name = "id") String id) {
GatewayReceiver config = new GatewayReceiver();
Expand All @@ -67,11 +65,10 @@ public ClusterManagementGetResult<GatewayReceiver, GatewayReceiverInfo> getGatew

@ApiOperation(value = "create gateway-receiver")
@PreAuthorize("@securityService.authorize('CLUSTER', 'MANAGE')")
@RequestMapping(method = RequestMethod.POST, value = GATEWAY_RECEIVERS_ENDPOINTS)
@PostMapping(GATEWAY_RECEIVERS_ENDPOINTS)
public ResponseEntity<ClusterManagementResult> createGatewayReceiver(
@RequestBody GatewayReceiver gatewayReceiverConfig) {
ClusterManagementResult result =
clusterManagementService.create(gatewayReceiverConfig);
ClusterManagementResult result = clusterManagementService.create(gatewayReceiverConfig);
return new ResponseEntity<>(result, HttpStatus.CREATED);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,36 +15,34 @@

package org.apache.geode.management.internal.rest.controllers;

import static org.apache.geode.management.configuration.Links.URI_VERSION;
import static org.apache.geode.management.configuration.Member.MEMBER_ENDPOINT;
import static org.apache.geode.management.internal.rest.controllers.AbstractManagementController.MANAGEMENT_API_VERSION;

import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.Extension;
import io.swagger.annotations.ExtensionProperty;
import org.apache.commons.lang3.StringUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import org.apache.geode.management.api.ClusterManagementGetResult;
import org.apache.geode.management.api.ClusterManagementListResult;
import org.apache.geode.management.configuration.Member;
import org.apache.geode.management.runtime.MemberInformation;

@Controller("members")
@RequestMapping(MANAGEMENT_API_VERSION)
@RestController("members")
@RequestMapping(URI_VERSION)
public class MemberManagementController extends AbstractManagementController {
@ApiOperation(value = "get member",
extensions = {@Extension(properties = {
@ExtensionProperty(name = "jqFilter",
value = ".result | .runtimeInfo[] | {name:.memberName,status:.status}")})})
@PreAuthorize("@securityService.authorize('CLUSTER', 'READ')")
@RequestMapping(method = RequestMethod.GET, value = MEMBER_ENDPOINT + "/{id}")
@ResponseBody
@GetMapping(MEMBER_ENDPOINT + "/{id}")
public ClusterManagementGetResult<Member, MemberInformation> getMember(
@PathVariable(name = "id") String id) {
Member config = new Member();
Expand All @@ -57,8 +55,7 @@ public ClusterManagementGetResult<Member, MemberInformation> getMember(
@ExtensionProperty(name = "jqFilter",
value = ".result[] | .runtimeInfo[] | {name:.memberName,status:.status}")})})
@PreAuthorize("@securityService.authorize('CLUSTER', 'READ')")
@RequestMapping(method = RequestMethod.GET, value = MEMBER_ENDPOINT)
@ResponseBody
@GetMapping(MEMBER_ENDPOINT)
public ClusterManagementListResult<Member, MemberInformation> listMembers(
@RequestParam(required = false) String id, @RequestParam(required = false) String group) {
Member filter = new Member();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,25 @@

package org.apache.geode.management.internal.rest.controllers;

import static org.apache.geode.management.configuration.Links.URI_VERSION;
import static org.apache.geode.management.configuration.Pdx.PDX_ENDPOINT;
import static org.apache.geode.management.internal.rest.controllers.AbstractManagementController.MANAGEMENT_API_VERSION;

import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import org.apache.geode.management.api.ClusterManagementResult;
import org.apache.geode.management.configuration.Pdx;

@Controller("pdxManagement")
@RequestMapping(MANAGEMENT_API_VERSION)
@RestController("pdxManagement")
@RequestMapping(URI_VERSION)
public class PdxManagementController extends AbstractManagementController {

@ApiOperation(value = "configure pdx")
Expand All @@ -43,11 +43,10 @@ public class PdxManagementController extends AbstractManagementController {
@ApiResponse(code = 409, message = "Entity already exists."),
@ApiResponse(code = 500, message = "GemFire throws an error or exception.")})
@PreAuthorize("@securityService.authorize('CLUSTER', 'MANAGE')")
@RequestMapping(method = RequestMethod.POST, value = PDX_ENDPOINT)
@PostMapping(PDX_ENDPOINT)
public ResponseEntity<ClusterManagementResult> configurePdx(
@RequestBody Pdx pdxType) {
ClusterManagementResult result = clusterManagementService.create(pdxType);
return new ResponseEntity<>(result,
HttpStatus.CREATED);
return new ResponseEntity<>(result, HttpStatus.CREATED);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,22 @@

package org.apache.geode.management.internal.rest.controllers;


import static org.apache.geode.management.internal.rest.controllers.AbstractManagementController.MANAGEMENT_API_VERSION;
import static org.apache.geode.management.configuration.Links.URI_VERSION;

import io.swagger.annotations.ApiOperation;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@ApiOperation(value = "ping")
@Controller("ping")
@RequestMapping(MANAGEMENT_API_VERSION)
@RequestMapping(URI_VERSION)
public class PingManagementController extends AbstractManagementController {

@RequestMapping(method = RequestMethod.GET, value = "/ping")
@GetMapping("/ping")
public ResponseEntity<String> ping() {
return new ResponseEntity<>("pong", HttpStatus.OK);
return new ResponseEntity<String>("pong", HttpStatus.OK);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

package org.apache.geode.management.internal.rest.controllers;

import static org.apache.geode.management.internal.rest.controllers.AbstractManagementController.MANAGEMENT_API_VERSION;
import static org.apache.geode.management.configuration.Links.URI_VERSION;
import static org.apache.geode.management.operation.RebalanceOperation.REBALANCE_ENDPOINT;

import java.util.Optional;
Expand All @@ -25,12 +25,12 @@
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import org.apache.geode.internal.security.SecurityService;
import org.apache.geode.management.api.ClusterManagementListOperationsResult;
Expand All @@ -40,12 +40,12 @@
import org.apache.geode.management.operation.RebalanceOperation;
import org.apache.geode.management.runtime.RebalanceResult;

@Controller("rebalanceOperation")
@RequestMapping(MANAGEMENT_API_VERSION)
@RestController("rebalanceOperation")
@RequestMapping(URI_VERSION)
public class RebalanceOperationController extends AbstractManagementController {
@ApiOperation(value = "start rebalance")
@PreAuthorize("@securityService.authorize('DATA', 'MANAGE')")
@RequestMapping(method = RequestMethod.POST, value = REBALANCE_ENDPOINT)
@PostMapping(REBALANCE_ENDPOINT)
public ResponseEntity<ClusterManagementOperationResult<RebalanceResult>> startRebalance(
@RequestBody RebalanceOperation operation) {
ClusterManagementOperationResult<RebalanceResult> result =
Expand All @@ -55,16 +55,14 @@ public ResponseEntity<ClusterManagementOperationResult<RebalanceResult>> startRe

@ApiOperation(value = "list rebalances")
@PreAuthorize("@securityService.authorize('DATA', 'MANAGE')")
@RequestMapping(method = RequestMethod.GET, value = REBALANCE_ENDPOINT)
@ResponseBody
@GetMapping(REBALANCE_ENDPOINT)
public ClusterManagementListOperationsResult<RebalanceResult> listRebalances() {
return clusterManagementService.list(new RebalanceOperation());
}

@ApiOperation(value = "check rebalance")
@PreAuthorize("@securityService.authorize('DATA', 'MANAGE')")
@RequestMapping(method = RequestMethod.GET, value = REBALANCE_ENDPOINT + "/{id}")
@ResponseBody
@GetMapping(REBALANCE_ENDPOINT + "/{id}")
public ResponseEntity<ClusterManagementOperationStatusResult<RebalanceResult>> checkRebalanceStatus(
@PathVariable String id) {
ClusterManagementOperationStatusResult<RebalanceResult> result =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@

package org.apache.geode.management.internal.rest.controllers;

import static org.apache.geode.management.configuration.Links.URI_VERSION;
import static org.apache.geode.management.configuration.Region.REGION_CONFIG_ENDPOINT;
import static org.apache.geode.management.internal.rest.controllers.AbstractManagementController.MANAGEMENT_API_VERSION;

import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
Expand All @@ -27,13 +27,14 @@
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import org.apache.geode.management.api.ClusterManagementGetResult;
import org.apache.geode.management.api.ClusterManagementListResult;
Expand All @@ -45,9 +46,10 @@
import org.apache.geode.security.ResourcePermission.Operation;
import org.apache.geode.security.ResourcePermission.Resource;

@Controller("regionManagement")
@RequestMapping(MANAGEMENT_API_VERSION)
@RestController("regionManagement")
@RequestMapping(URI_VERSION)
public class RegionManagementController extends AbstractManagementController {
private static final String INDEXES = "/indexes";

@ApiOperation(value = "create region")
@ApiResponses({@ApiResponse(code = 200, message = "OK."),
Expand All @@ -56,7 +58,7 @@ public class RegionManagementController extends AbstractManagementController {
@ApiResponse(code = 409, message = "Region already exist."),
@ApiResponse(code = 500, message = "GemFire throws an error or exception.")})
@PreAuthorize("@securityService.authorize('DATA', 'MANAGE')")
@RequestMapping(method = RequestMethod.POST, value = REGION_CONFIG_ENDPOINT)
@PostMapping(REGION_CONFIG_ENDPOINT)
public ResponseEntity<ClusterManagementResult> createRegion(
@RequestBody Region regionConfig) {
ClusterManagementResult result =
Expand All @@ -70,8 +72,7 @@ public ResponseEntity<ClusterManagementResult> createRegion(
@ExtensionProperty(name = "jqFilter",
value = ".result[] | .runtimeInfo[] + .configuration | {name:.name,type:.type,entryCount:.entryCount}")})})
@PreAuthorize("@securityService.authorize('CLUSTER', 'READ')")
@RequestMapping(method = RequestMethod.GET, value = REGION_CONFIG_ENDPOINT)
@ResponseBody
@GetMapping(REGION_CONFIG_ENDPOINT)
public ClusterManagementListResult<Region, RuntimeRegionInfo> listRegion(
@RequestParam(required = false) String id,
@RequestParam(required = false) String group) {
Expand All @@ -89,8 +90,7 @@ public ClusterManagementListResult<Region, RuntimeRegionInfo> listRegion(
extensions = {@Extension(properties = {
@ExtensionProperty(name = "jqFilter",
value = ".result | .runtimeInfo[] + .configuration | {name:.name,type:.type,entryCount:.entryCount}")})})
@RequestMapping(method = RequestMethod.GET, value = REGION_CONFIG_ENDPOINT + "/{id}")
@ResponseBody
@GetMapping(REGION_CONFIG_ENDPOINT + "/{id}")
public ClusterManagementGetResult<Region, RuntimeRegionInfo> getRegion(
@PathVariable(name = "id") String id) {
securityService.authorize(Resource.CLUSTER, Operation.READ, id);
Expand All @@ -101,8 +101,7 @@ public ClusterManagementGetResult<Region, RuntimeRegionInfo> getRegion(

@ApiOperation(value = "delete region")
@PreAuthorize("@securityService.authorize('DATA', 'MANAGE')")
@RequestMapping(method = RequestMethod.DELETE, value = REGION_CONFIG_ENDPOINT + "/{id}")
@ResponseBody
@DeleteMapping(REGION_CONFIG_ENDPOINT + "/{id}")
public ClusterManagementResult deleteRegion(
@PathVariable(name = "id") String id,
@RequestParam(required = false) String group) {
Expand All @@ -118,9 +117,7 @@ public ClusterManagementResult deleteRegion(
extensions = {@Extension(properties = {
@ExtensionProperty(name = "jqFilter",
value = ".result[] | .configuration | {name:.name,expression:.expression}")})})
@RequestMapping(method = RequestMethod.GET,
value = REGION_CONFIG_ENDPOINT + "/{regionName}/indexes")
@ResponseBody
@GetMapping(REGION_CONFIG_ENDPOINT + "/{regionName}" + INDEXES)
@PreAuthorize("@securityService.authorize('CLUSTER', 'READ', 'QUERY')")
public ClusterManagementListResult<Index, RuntimeInfo> listIndex(
@PathVariable String regionName,
Expand All @@ -138,8 +135,7 @@ public ClusterManagementListResult<Index, RuntimeInfo> listIndex(
extensions = {@Extension(properties = {
@ExtensionProperty(name = "jqFilter",
value = ".result[] | .configuration | {name:.name,expression:.expression,regionPath:.regionPath}")})})
@RequestMapping(method = RequestMethod.GET, value = "/indexes")
@ResponseBody
@GetMapping(INDEXES)
@PreAuthorize("@securityService.authorize('CLUSTER', 'READ', 'QUERY')")
public ClusterManagementListResult<Index, RuntimeInfo> listAllIndex(
@RequestParam(required = false, name = "id") String indexName) {
Expand All @@ -154,9 +150,7 @@ public ClusterManagementListResult<Index, RuntimeInfo> listAllIndex(
extensions = {@Extension(properties = {
@ExtensionProperty(name = "jqFilter",
value = ".result | .configuration | {name:.name,expression:.expression}")})})
@RequestMapping(method = RequestMethod.GET,
value = REGION_CONFIG_ENDPOINT + "/{regionName}/indexes/{id}")
@ResponseBody
@GetMapping(REGION_CONFIG_ENDPOINT + "/{regionName}" + INDEXES + "/{id}")
@PreAuthorize("@securityService.authorize('CLUSTER', 'READ', 'QUERY')")
public ClusterManagementGetResult<Index, RuntimeInfo> getIndex(
@PathVariable String regionName,
Expand Down

0 comments on commit a905e70

Please sign in to comment.