Search in sources :

Example 16 with CanDistro

use of com.alibaba.nacos.naming.web.CanDistro in project nacos by alibaba.

the class InstanceControllerV2 method update.

/**
 * Update 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 update
 */
@CanDistro
@PutMapping
@Secured(action = ActionTypes.WRITE)
public String update(@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.updateInstance(namespaceId, serviceName, instance);
    return "ok";
}
Also used : Instance(com.alibaba.nacos.api.naming.pojo.Instance) Secured(com.alibaba.nacos.auth.annotation.Secured) PutMapping(org.springframework.web.bind.annotation.PutMapping) CanDistro(com.alibaba.nacos.naming.web.CanDistro)

Example 17 with CanDistro

use of com.alibaba.nacos.naming.web.CanDistro in project nacos by alibaba.

the class InstanceControllerV2 method batchUpdateInstanceMetadata.

/**
 * Batch update instance's metadata. old key exist = update, old key not exist = add.
 *
 * @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
@PutMapping(value = "/metadata/batch")
@Secured(action = ActionTypes.WRITE)
public ObjectNode batchUpdateInstanceMetadata(@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.batchUpdateMetadata(namespaceId, instanceOperationInfo, targetMetadata);
    ObjectNode result = JacksonUtils.createEmptyJsonNode();
    ArrayNode ipArray = JacksonUtils.createEmptyArrayNode();
    for (String ip : operatedInstances) {
        ipArray.add(ip);
    }
    result.replace("updated", ipArray);
    return result;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Instance(com.alibaba.nacos.api.naming.pojo.Instance) InstanceOperationInfo(com.alibaba.nacos.naming.pojo.InstanceOperationInfo) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) Secured(com.alibaba.nacos.auth.annotation.Secured) PutMapping(org.springframework.web.bind.annotation.PutMapping) CanDistro(com.alibaba.nacos.naming.web.CanDistro)

Aggregations

Secured (com.alibaba.nacos.auth.annotation.Secured)17 CanDistro (com.alibaba.nacos.naming.web.CanDistro)17 Instance (com.alibaba.nacos.api.naming.pojo.Instance)13 PutMapping (org.springframework.web.bind.annotation.PutMapping)7 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)6 DeleteMapping (org.springframework.web.bind.annotation.DeleteMapping)5 InstanceOperationInfo (com.alibaba.nacos.naming.pojo.InstanceOperationInfo)4 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)4 PostMapping (org.springframework.web.bind.annotation.PostMapping)3 InstancePatchObject (com.alibaba.nacos.naming.core.InstancePatchObject)2 RsInfo (com.alibaba.nacos.naming.healthcheck.RsInfo)2 BeatInfoInstanceBuilder (com.alibaba.nacos.naming.pojo.instance.BeatInfoInstanceBuilder)2 PatchMapping (org.springframework.web.bind.annotation.PatchMapping)2