use of com.alibaba.nacos.naming.web.CanDistro in project nacos by alibaba.
the class InstanceControllerV2 method register.
/**
* Register new instance.
*
* @param namespaceId namespace id
* @param serviceName service name
* @param metadata service metadata
* @param cluster service cluster
* @param ip instance ip
* @param port instance port
* @param healthy instance healthy
* @param weight instance weight
* @param enabled instance enabled
* @param ephemeral instance ephemeral
* @return 'ok' if success
* @throws Exception any error during register
*/
@CanDistro
@PostMapping
@Secured(action = ActionTypes.WRITE)
public String register(@RequestParam(defaultValue = Constants.DEFAULT_NAMESPACE_ID) String namespaceId, @RequestParam String serviceName, @RequestParam String ip, @RequestParam(defaultValue = UtilsAndCommons.DEFAULT_CLUSTER_NAME) String cluster, @RequestParam Integer port, @RequestParam(defaultValue = "true") Boolean healthy, @RequestParam(defaultValue = "1") Double weight, @RequestParam(defaultValue = "true") Boolean enabled, @RequestParam String metadata, @RequestParam Boolean ephemeral) throws Exception {
NamingUtils.checkServiceNameFormat(serviceName);
checkWeight(weight);
final Instance instance = InstanceBuilder.newBuilder().setServiceName(serviceName).setIp(ip).setClusterName(cluster).setPort(port).setHealthy(healthy).setWeight(weight).setEnabled(enabled).setMetadata(UtilsAndCommons.parseMetadata(metadata)).setEphemeral(ephemeral).build();
if (ephemeral == null) {
instance.setEphemeral((switchDomain.isDefaultInstanceEphemeral()));
}
instanceServiceV2.registerInstance(namespaceId, serviceName, instance);
return "ok";
}
use of com.alibaba.nacos.naming.web.CanDistro in project nacos by alibaba.
the class InstanceControllerV2 method patch.
/**
* Patch instance.
*
* @param namespaceId namespace id
* @param serviceName service name
* @param metadata service metadata
* @param cluster service cluster
* @param ip instance ip
* @param port instance port
* @param weight instance weight
* @param enabled instance enabled
* @return 'ok' if success
* @throws Exception any error during patch
*/
@CanDistro
@PatchMapping
@Secured(action = ActionTypes.WRITE)
public String patch(@RequestParam(defaultValue = Constants.DEFAULT_NAMESPACE_ID) String namespaceId, @RequestParam String serviceName, @RequestParam String ip, @RequestParam(defaultValue = UtilsAndCommons.DEFAULT_CLUSTER_NAME) String cluster, @RequestParam Integer port, @RequestParam Double weight, @RequestParam Boolean enabled, @RequestParam String metadata) throws Exception {
NamingUtils.checkServiceNameFormat(serviceName);
InstancePatchObject patchObject = new InstancePatchObject(cluster, ip, port);
if (StringUtils.isNotBlank(metadata)) {
patchObject.setMetadata(UtilsAndCommons.parseMetadata(metadata));
}
if (weight != null) {
checkWeight(weight);
patchObject.setWeight(weight);
}
if (enabled != null) {
patchObject.setEnabled(enabled);
}
instanceServiceV2.patchInstance(namespaceId, serviceName, patchObject);
return "ok";
}
use of com.alibaba.nacos.naming.web.CanDistro in project nacos by alibaba.
the class InstanceControllerV2 method deregister.
/**
* Deregister instances.
*
* @param namespaceId namespace id
* @param serviceName service name
* @param metadata service metadata
* @param cluster service cluster
* @param ip instance ip
* @param port instance port
* @param healthy instance healthy
* @param weight instance weight
* @param enabled instance enabled
* @param ephemeral instance ephemeral
* @return 'ok' if success
* @throws Exception any error during deregister
*/
@CanDistro
@DeleteMapping
@Secured(action = ActionTypes.WRITE)
public String deregister(@RequestParam(defaultValue = Constants.DEFAULT_NAMESPACE_ID) String namespaceId, @RequestParam String serviceName, @RequestParam String ip, @RequestParam(defaultValue = UtilsAndCommons.DEFAULT_CLUSTER_NAME) String cluster, @RequestParam Integer port, @RequestParam(defaultValue = "true") Boolean healthy, @RequestParam(defaultValue = "1") Double weight, @RequestParam(defaultValue = "true") Boolean enabled, @RequestParam String metadata, @RequestParam Boolean ephemeral) throws Exception {
NamingUtils.checkServiceNameFormat(serviceName);
checkWeight(weight);
final Instance instance = InstanceBuilder.newBuilder().setServiceName(serviceName).setIp(ip).setClusterName(cluster).setPort(port).setHealthy(healthy).setWeight(weight).setEnabled(enabled).setMetadata(UtilsAndCommons.parseMetadata(metadata)).setEphemeral(ephemeral).build();
if (ephemeral == null) {
instance.setEphemeral((switchDomain.isDefaultInstanceEphemeral()));
}
instanceServiceV2.removeInstance(namespaceId, serviceName, instance);
return "ok";
}
use of com.alibaba.nacos.naming.web.CanDistro 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.naming.web.CanDistro in project nacos by alibaba.
the class UpgradeOpsController method updateInstance.
/**
* Update instance.
*
* @param request http request
* @return 'ok' if success
* @throws Exception any error during update
*/
@CanDistro
@PutMapping("/instance")
@Secured(action = ActionTypes.WRITE)
public String updateInstance(@RequestParam(defaultValue = "v2", required = false) String ver, 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(ver).updateInstance(namespaceId, serviceName, instance);
return "ok";
}
Aggregations