use of com.alibaba.nacos.auth.annotation.Secured in project nacos by alibaba.
the class ServiceController method list.
/**
* List all service names.
*
* @param request http request
* @return all service names
* @throws Exception exception
*/
@GetMapping("/list")
@Secured(action = ActionTypes.READ)
public ObjectNode list(HttpServletRequest request) throws Exception {
final int pageNo = NumberUtils.toInt(WebUtils.required(request, "pageNo"));
final int pageSize = NumberUtils.toInt(WebUtils.required(request, "pageSize"));
String namespaceId = WebUtils.optional(request, CommonParams.NAMESPACE_ID, Constants.DEFAULT_NAMESPACE_ID);
String groupName = WebUtils.optional(request, CommonParams.GROUP_NAME, Constants.DEFAULT_GROUP);
String selectorString = WebUtils.optional(request, "selector", StringUtils.EMPTY);
ObjectNode result = JacksonUtils.createEmptyJsonNode();
Collection<String> serviceNameList = getServiceOperator().listService(namespaceId, groupName, selectorString);
result.put("count", serviceNameList.size());
result.replace("doms", JacksonUtils.transferToJsonNode(ServiceUtil.pageServiceName(pageNo, pageSize, serviceNameList)));
return result;
}
use of com.alibaba.nacos.auth.annotation.Secured in project nacos by alibaba.
the class ServiceControllerV2 method update.
/**
* Update service.
*
* @param namespaceId namespace id
* @param serviceName service name
* @param protectThreshold protect threshold
* @param metadata service metadata
* @param selector selector
* @return 'ok' if success
* @throws Exception exception
*/
@PutMapping(value = "/{serviceName}")
@Secured(action = ActionTypes.WRITE)
public RestResult<String> update(@RequestParam(defaultValue = Constants.DEFAULT_NAMESPACE_ID) String namespaceId, @PathVariable String serviceName, @RequestParam(defaultValue = Constants.DEFAULT_GROUP) String groupName, @RequestParam(required = false, defaultValue = "0.0F") float protectThreshold, @RequestParam(defaultValue = StringUtils.EMPTY) String metadata, @RequestParam(defaultValue = StringUtils.EMPTY) String selector) throws Exception {
ServiceMetadata serviceMetadata = new ServiceMetadata();
serviceMetadata.setProtectThreshold(protectThreshold);
serviceMetadata.setExtendData(UtilsAndCommons.parseMetadata(metadata));
serviceMetadata.setSelector(parseSelector(selector));
Service service = Service.newService(namespaceId, groupName, serviceName);
serviceOperatorV2.update(service, serviceMetadata);
return RestResultUtils.success("ok");
}
use of com.alibaba.nacos.auth.annotation.Secured in project nacos by alibaba.
the class ServiceControllerV2 method create.
/**
* Create a new service. This API will create a persistence service.
*
* @param namespaceId namespace id
* @param serviceName service name
* @param protectThreshold protect threshold
* @param metadata service metadata
* @param selector selector
* @return 'ok' if success
* @throws Exception exception
*/
@PostMapping(value = "/{serviceName}")
@Secured(action = ActionTypes.WRITE)
public RestResult<String> create(@RequestParam(defaultValue = Constants.DEFAULT_NAMESPACE_ID) String namespaceId, @PathVariable String serviceName, @RequestParam(defaultValue = Constants.DEFAULT_GROUP) String groupName, @RequestParam(required = false, defaultValue = "false") boolean ephemeral, @RequestParam(required = false, defaultValue = "0.0F") float protectThreshold, @RequestParam(defaultValue = StringUtils.EMPTY) String metadata, @RequestParam(defaultValue = StringUtils.EMPTY) String selector) throws Exception {
ServiceMetadata serviceMetadata = new ServiceMetadata();
serviceMetadata.setProtectThreshold(protectThreshold);
serviceMetadata.setSelector(parseSelector(selector));
serviceMetadata.setExtendData(UtilsAndCommons.parseMetadata(metadata));
serviceMetadata.setEphemeral(ephemeral);
serviceOperatorV2.create(Service.newService(namespaceId, groupName, serviceName, ephemeral), serviceMetadata);
return RestResultUtils.success("ok");
}
use of com.alibaba.nacos.auth.annotation.Secured in project nacos by alibaba.
the class UpgradeOpsController method deregisterInstance.
/**
* Deregister instances.
*
* @param request http request
* @return 'ok' if success
* @throws Exception any error during deregister
*/
@CanDistro
@DeleteMapping("/instance")
@Secured(action = ActionTypes.WRITE)
public String deregisterInstance(@RequestParam(defaultValue = "v2", required = false) String ver, HttpServletRequest request) throws Exception {
Instance instance = HttpRequestInstanceBuilder.newBuilder().setDefaultInstanceEphemeral(switchDomain.isDefaultInstanceEphemeral()).setRequest(request).build();
String namespaceId = WebUtils.optional(request, CommonParams.NAMESPACE_ID, Constants.DEFAULT_NAMESPACE_ID);
String serviceName = WebUtils.required(request, CommonParams.SERVICE_NAME);
NamingUtils.checkServiceNameFormat(serviceName);
getInstanceOperator(ver).removeInstance(namespaceId, serviceName, instance);
return "ok";
}
use of com.alibaba.nacos.auth.annotation.Secured in project nacos by alibaba.
the class UpgradeOpsController method listService.
/**
* List all service names.
*
* @param request http request
* @return all service names
* @throws Exception exception
*/
@GetMapping("/service/list")
@Secured(action = ActionTypes.READ)
public ObjectNode listService(@RequestParam(defaultValue = "v2", required = false) String ver, HttpServletRequest request) throws Exception {
final int pageNo = NumberUtils.toInt(WebUtils.required(request, "pageNo"));
final int pageSize = NumberUtils.toInt(WebUtils.required(request, "pageSize"));
String namespaceId = WebUtils.optional(request, CommonParams.NAMESPACE_ID, Constants.DEFAULT_NAMESPACE_ID);
String groupName = WebUtils.optional(request, CommonParams.GROUP_NAME, Constants.DEFAULT_GROUP);
String selectorString = WebUtils.optional(request, "selector", StringUtils.EMPTY);
ObjectNode result = JacksonUtils.createEmptyJsonNode();
Collection<String> serviceNameList = getServiceOperator(ver).listService(namespaceId, groupName, selectorString);
result.put("count", serviceNameList.size());
result.replace("doms", JacksonUtils.transferToJsonNode(ServiceUtil.pageServiceName(pageNo, pageSize, serviceNameList)));
return result;
}
Aggregations