use of com.alibaba.nacos.auth.annotation.Secured in project nacos by alibaba.
the class InstanceController method register.
/**
* Register new instance.
*
* @param request http request
* @return 'ok' if success
* @throws Exception any error during register
*/
@CanDistro
@PostMapping
@Secured(action = ActionTypes.WRITE)
public String register(HttpServletRequest request) throws Exception {
final String namespaceId = WebUtils.optional(request, CommonParams.NAMESPACE_ID, Constants.DEFAULT_NAMESPACE_ID);
final String serviceName = WebUtils.required(request, CommonParams.SERVICE_NAME);
NamingUtils.checkServiceNameFormat(serviceName);
final Instance instance = HttpRequestInstanceBuilder.newBuilder().setDefaultInstanceEphemeral(switchDomain.isDefaultInstanceEphemeral()).setRequest(request).build();
getInstanceOperator().registerInstance(namespaceId, serviceName, instance);
return "ok";
}
use of com.alibaba.nacos.auth.annotation.Secured in project nacos by alibaba.
the class InstanceController method list.
/**
* Get all instance of input service.
*
* @param request http request
* @return list of instance
* @throws Exception any error during list
*/
@GetMapping("/list")
@Secured(action = ActionTypes.READ)
public Object list(HttpServletRequest request) throws Exception {
String namespaceId = WebUtils.optional(request, CommonParams.NAMESPACE_ID, Constants.DEFAULT_NAMESPACE_ID);
String serviceName = WebUtils.required(request, CommonParams.SERVICE_NAME);
NamingUtils.checkServiceNameFormat(serviceName);
String agent = WebUtils.getUserAgent(request);
String clusters = WebUtils.optional(request, "clusters", StringUtils.EMPTY);
String clientIP = WebUtils.optional(request, "clientIP", StringUtils.EMPTY);
int udpPort = Integer.parseInt(WebUtils.optional(request, "udpPort", "0"));
boolean healthyOnly = Boolean.parseBoolean(WebUtils.optional(request, "healthyOnly", "false"));
String app = WebUtils.optional(request, "app", StringUtils.EMPTY);
Subscriber subscriber = new Subscriber(clientIP + ":" + udpPort, agent, app, clientIP, namespaceId, serviceName, udpPort, clusters);
return getInstanceOperator().listInstance(namespaceId, serviceName, subscriber, clusters, healthyOnly);
}
use of com.alibaba.nacos.auth.annotation.Secured in project nacos by alibaba.
the class InstanceController method update.
/**
* Update instance.
*
* @param request http request
* @return 'ok' if success
* @throws Exception any error during update
*/
@CanDistro
@PutMapping
@Secured(action = ActionTypes.WRITE)
public String update(HttpServletRequest request) throws Exception {
String namespaceId = WebUtils.optional(request, CommonParams.NAMESPACE_ID, Constants.DEFAULT_NAMESPACE_ID);
String serviceName = WebUtils.required(request, CommonParams.SERVICE_NAME);
NamingUtils.checkServiceNameFormat(serviceName);
Instance instance = HttpRequestInstanceBuilder.newBuilder().setDefaultInstanceEphemeral(switchDomain.isDefaultInstanceEphemeral()).setRequest(request).build();
getInstanceOperator().updateInstance(namespaceId, serviceName, instance);
return "ok";
}
use of com.alibaba.nacos.auth.annotation.Secured in project nacos by alibaba.
the class InstanceControllerV2 method detail.
/**
* Get detail information of specified instance.
*
* @param namespaceId service namespaceId
* @param serviceName service serviceName
* @param ip instance ip
* @param clusterName service clusterName
* @param port instance port
* @return detail information of instance
* @throws Exception any error during get
*/
@GetMapping
@Secured(action = ActionTypes.READ)
public ObjectNode detail(@RequestParam(defaultValue = Constants.DEFAULT_NAMESPACE_ID) String namespaceId, @RequestParam String serviceName, @RequestParam String ip, @RequestParam(defaultValue = UtilsAndCommons.DEFAULT_CLUSTER_NAME) String clusterName, @RequestParam Integer port) throws Exception {
NamingUtils.checkServiceNameFormat(serviceName);
Instance instance = instanceServiceV2.getInstance(namespaceId, serviceName, clusterName, ip, port);
ObjectNode result = JacksonUtils.createEmptyJsonNode();
result.put("service", serviceName);
result.put("ip", ip);
result.put("port", port);
result.put("clusterName", clusterName);
result.put("weight", instance.getWeight());
result.put("healthy", instance.isHealthy());
result.put("instanceId", instance.getInstanceId());
result.set("metadata", JacksonUtils.transferToJsonNode(instance.getMetadata()));
return result;
}
use of com.alibaba.nacos.auth.annotation.Secured in project nacos by alibaba.
the class InstanceControllerV2 method batchDeleteInstanceMetadata.
/**
* Batch delete instance's metadata. old key exist = delete, old key not exist = not operate
*
* @param namespaceId namespace id
* @param serviceName service name
* @param metadata service metadata
* @param consistencyType consistencyType
* @param instances instances info
* @return success updated instances. such as '{"updated":["2.2.2.2:8080:unknown:xxxx-cluster:ephemeral"}'.
* @throws Exception any error during update
* @since 1.4.0
*/
@CanDistro
@DeleteMapping("/metadata/batch")
@Secured(action = ActionTypes.WRITE)
public ObjectNode batchDeleteInstanceMetadata(@RequestParam(defaultValue = Constants.DEFAULT_NAMESPACE_ID) String namespaceId, @RequestParam String serviceName, @RequestParam(defaultValue = "") String consistencyType, @RequestParam(defaultValue = "") String instances, @RequestParam String metadata) throws Exception {
List<Instance> targetInstances = parseBatchInstances(instances);
Map<String, String> targetMetadata = UtilsAndCommons.parseMetadata(metadata);
InstanceOperationInfo instanceOperationInfo = buildOperationInfo(serviceName, consistencyType, targetInstances);
List<String> operatedInstances = instanceServiceV2.batchDeleteMetadata(namespaceId, instanceOperationInfo, targetMetadata);
ObjectNode result = JacksonUtils.createEmptyJsonNode();
ArrayNode ipArray = JacksonUtils.createEmptyArrayNode();
for (String ip : operatedInstances) {
ipArray.add(ip);
}
result.replace("updated", ipArray);
return result;
}
Aggregations