Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#1368] add flag control graceful invalid call service-center api #1369

Merged
merged 4 commits into from
Aug 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

import javax.annotation.Nullable;

import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
Expand Down Expand Up @@ -49,16 +48,19 @@ public NacosGracefulEndpoint(NacosServiceRegistry nacosServiceRegistry, NacosReg

@WriteOperation
public void gracefulUpperAndDown(@Nullable String status) {
if (StringUtils.isEmpty(status)) {
return;
}
if (GovernanceProperties.GRASEFUL_STATUS_UPPER.equalsIgnoreCase(status)) {
if (GovernanceProperties.GRASEFUL_STATUS_UPPER.equalsIgnoreCase(status)
&& !nacosAutoServiceRegistration.isEnabled()) {
nacosAutoServiceRegistration.setRegistryEnabled(true);
nacosAutoServiceRegistration.registryExtend();
} else if (GovernanceProperties.GRASEFUL_STATUS_DOWN.equalsIgnoreCase(status)) {
return;
}
if (GovernanceProperties.GRASEFUL_STATUS_DOWN.equalsIgnoreCase(status)
&& nacosAutoServiceRegistration.isEnabled()) {
nacosServiceRegistry.deregister(nacosRegistration);
} else {
LOGGER.warn("operation is not allowed, status: " + status);
nacosAutoServiceRegistration.setRegistryEnabled(false);
return;
}
LOGGER.info("operation is not allowed, status: " + status + ", registration_enabled: "
+ nacosAutoServiceRegistration.isEnabled());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ protected Object getConfiguration() {
}

@Override
protected boolean isEnabled() {
public boolean isEnabled() {
return this.registryEnabled;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ public void deregister(Registration registration) {
serviceManager.getNamingService().deregisterInstance(serviceId, group, registration.getHost(),
registration.getPort(), nacosDiscoveryProperties.getClusterName());
successCount++;
LOGGER.info("nacos de-register {} {}:{} finished", serviceId, instance.getIp(), instance.getPort());
} catch (Exception e) {
LOGGER.error("de-register service [{}] from Nacos Server [{}] failed.", registration.getServiceId(),
serviceManager.getServerAddr(), e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@

import javax.annotation.Nullable;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.servicecomb.service.center.client.model.MicroserviceInstanceStatus;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
Expand All @@ -46,11 +47,24 @@ public ServicecombGracefulEndpoint(ServiceCombServiceRegistry serviceCombService
@WriteOperation
public void gracefulUpperAndDown(@Nullable String status) {
if (StringUtils.isEmpty(status)
|| (!GovernanceProperties.GRASEFUL_STATUS_UPPER.equalsIgnoreCase(status)
&& !GovernanceProperties.GRASEFUL_STATUS_DOWN.equalsIgnoreCase(status))) {
LOGGER.warn("status input " + status + " is not a valid value.");
|| StringUtils.isEmpty(serviceCombRegistration.getMicroserviceInstance().getServiceId())
|| StringUtils.isEmpty(serviceCombRegistration.getMicroserviceInstance().getInstanceId())) {
LOGGER.info("operation is not allowed, status is null or registration is not ok.");
return;
}
serviceCombServiceRegistry.setStatus(serviceCombRegistration, status.toUpperCase());
if (GovernanceProperties.GRASEFUL_STATUS_UPPER.equalsIgnoreCase(status)
&& MicroserviceInstanceStatus.DOWN == serviceCombRegistration.getMicroserviceInstance().getStatus()) {
serviceCombServiceRegistry.setStatus(serviceCombRegistration, status.toUpperCase());
LOGGER.info("servicecomb graceful update status success, status: " + status);
return;
}
if (GovernanceProperties.GRASEFUL_STATUS_DOWN.equalsIgnoreCase(status)
&& MicroserviceInstanceStatus.UP == serviceCombRegistration.getMicroserviceInstance().getStatus()) {
serviceCombServiceRegistry.setStatus(serviceCombRegistration, status.toUpperCase());
LOGGER.info("servicecomb graceful update status success, status: " + status);
return;
}
LOGGER.info("operation is not allowed, status: " + status + ", instanceStatus: "
+ serviceCombRegistration.getMicroserviceInstance().getStatus());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ public void setStatus(ServiceCombRegistration registration, String status) {
try {
serviceCenterClient.updateMicroserviceInstanceStatus(registration.getMicroserviceInstance().getServiceId(),
registration.getMicroserviceInstance().getInstanceId(), MicroserviceInstanceStatus.valueOf(status));
registration.getMicroserviceInstance().setStatus(MicroserviceInstanceStatus.valueOf(status));
} catch (OperationException e) {
LOGGER.error("setStatus failed", e);
}
Expand Down
Loading