|
|
@ -22,12 +22,15 @@ import com.tencent.cloud.rpc.enhancement.plugin.EnhancedPlugin;
|
|
|
|
import com.tencent.cloud.rpc.enhancement.plugin.EnhancedPluginContext;
|
|
|
|
import com.tencent.cloud.rpc.enhancement.plugin.EnhancedPluginContext;
|
|
|
|
import com.tencent.cloud.rpc.enhancement.plugin.EnhancedPluginType;
|
|
|
|
import com.tencent.cloud.rpc.enhancement.plugin.EnhancedPluginType;
|
|
|
|
import com.tencent.cloud.rpc.enhancement.plugin.PolarisEnhancedPluginUtils;
|
|
|
|
import com.tencent.cloud.rpc.enhancement.plugin.PolarisEnhancedPluginUtils;
|
|
|
|
|
|
|
|
import com.tencent.cloud.rpc.enhancement.plugin.assembly.AssemblyMetadataProvider;
|
|
|
|
import com.tencent.cloud.rpc.enhancement.plugin.assembly.AssemblyRequestContext;
|
|
|
|
import com.tencent.cloud.rpc.enhancement.plugin.assembly.AssemblyRequestContext;
|
|
|
|
import com.tencent.cloud.rpc.enhancement.plugin.assembly.AssemblyResponseContext;
|
|
|
|
import com.tencent.cloud.rpc.enhancement.plugin.assembly.AssemblyResponseContext;
|
|
|
|
|
|
|
|
import com.tencent.cloud.rpc.enhancement.transformer.InstanceTransformer;
|
|
|
|
import com.tencent.polaris.api.pojo.ServiceKey;
|
|
|
|
import com.tencent.polaris.api.pojo.ServiceKey;
|
|
|
|
import com.tencent.polaris.api.rpc.RequestContext;
|
|
|
|
import com.tencent.polaris.api.rpc.RequestContext;
|
|
|
|
import com.tencent.polaris.assembly.api.AssemblyAPI;
|
|
|
|
import com.tencent.polaris.assembly.api.AssemblyAPI;
|
|
|
|
import com.tencent.polaris.assembly.api.pojo.AfterRequest;
|
|
|
|
import com.tencent.polaris.assembly.api.pojo.AfterRequest;
|
|
|
|
|
|
|
|
import com.tencent.polaris.assembly.api.pojo.Capability;
|
|
|
|
|
|
|
|
|
|
|
|
import org.springframework.core.Ordered;
|
|
|
|
import org.springframework.core.Ordered;
|
|
|
|
|
|
|
|
|
|
|
@ -40,8 +43,11 @@ public class AssemblyClientExceptionHook implements EnhancedPlugin {
|
|
|
|
|
|
|
|
|
|
|
|
private final AssemblyAPI assemblyAPI;
|
|
|
|
private final AssemblyAPI assemblyAPI;
|
|
|
|
|
|
|
|
|
|
|
|
public AssemblyClientExceptionHook(AssemblyAPI assemblyAPI) {
|
|
|
|
private final InstanceTransformer instanceTransformer;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public AssemblyClientExceptionHook(AssemblyAPI assemblyAPI, InstanceTransformer instanceTransformer) {
|
|
|
|
this.assemblyAPI = assemblyAPI;
|
|
|
|
this.assemblyAPI = assemblyAPI;
|
|
|
|
|
|
|
|
this.instanceTransformer = instanceTransformer;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
@ -51,17 +57,21 @@ public class AssemblyClientExceptionHook implements EnhancedPlugin {
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void run(EnhancedPluginContext context) {
|
|
|
|
public void run(EnhancedPluginContext context) {
|
|
|
|
|
|
|
|
|
|
|
|
AfterRequest afterRequest = new AfterRequest();
|
|
|
|
AfterRequest afterRequest = new AfterRequest();
|
|
|
|
afterRequest.setTargetService(new ServiceKey(MetadataContext.LOCAL_NAMESPACE, context.getTargetServiceInstance().getServiceId()));
|
|
|
|
afterRequest.setCapabilities(new Capability[]{Capability.ALL});
|
|
|
|
RequestContext requestContext = new AssemblyRequestContext(
|
|
|
|
afterRequest.setRequestContext(new AssemblyRequestContext(
|
|
|
|
context.getRequest(),
|
|
|
|
context.getRequest(),
|
|
|
|
new ServiceKey(MetadataContext.LOCAL_NAMESPACE, context.getLocalServiceInstance().getServiceId()),
|
|
|
|
new ServiceKey(MetadataContext.LOCAL_NAMESPACE, context.getLocalServiceInstance().getServiceId()),
|
|
|
|
context.getLocalServiceInstance().getHost()
|
|
|
|
context.getLocalServiceInstance().getHost()
|
|
|
|
);
|
|
|
|
));
|
|
|
|
afterRequest.setRequestContext(requestContext);
|
|
|
|
afterRequest.setResponseContext(new AssemblyResponseContext(null, context.getThrowable()));
|
|
|
|
|
|
|
|
afterRequest.setMetadataProvider(new AssemblyMetadataProvider(context.getLocalServiceInstance(), MetadataContext.LOCAL_NAMESPACE));
|
|
|
|
AssemblyResponseContext responseContext = new AssemblyResponseContext(null, context.getThrowable());
|
|
|
|
afterRequest.setDelay(context.getDelay());
|
|
|
|
afterRequest.setResponseContext(responseContext);
|
|
|
|
afterRequest.setRouteLabels(PolarisEnhancedPluginUtils.getLabelMap(context.getRequest().getHttpHeaders()));
|
|
|
|
|
|
|
|
// TargetService and TargetInstance only exist in client side
|
|
|
|
|
|
|
|
afterRequest.setTargetService(new ServiceKey(MetadataContext.LOCAL_NAMESPACE, context.getTargetServiceInstance().getServiceId()));
|
|
|
|
|
|
|
|
afterRequest.setTargetInstance(instanceTransformer.transform(context.getTargetServiceInstance()));
|
|
|
|
|
|
|
|
|
|
|
|
assemblyAPI.afterCallService(afterRequest);
|
|
|
|
assemblyAPI.afterCallService(afterRequest);
|
|
|
|
}
|
|
|
|
}
|
|
|
|