Java Code Examples for org.apache.servicecomb.core.Invocation#getMicroserviceName()

The following examples show how to use org.apache.servicecomb.core.Invocation#getMicroserviceName() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: IsolationServerEvent.java    From servicecomb-java-chassis with Apache License 2.0 6 votes vote down vote up
public IsolationServerEvent(Invocation invocation, MicroserviceInstance instance,
    ServiceCombServerStats serverStats,
    IsolationDiscoveryFilter.Settings settings, Type type, Endpoint endpoint) {
  super(type);
  this.microserviceName = invocation.getMicroserviceName();
  this.endpoint = endpoint;
  this.currentTotalRequest = serverStats.getTotalRequests();
  this.currentCountinuousFailureCount = serverStats.getCountinuousFailureCount();
  this.currentErrorPercentage = serverStats.getFailedRate();
  this.minIsolationTime = settings.minIsolationTime;
  this.enableRequestThreshold = settings.enableRequestThreshold;
  this.continuousFailureThreshold = settings.continuousFailureThreshold;
  this.errorThresholdPercentage = settings.errorThresholdPercentage;
  this.singleTestTime = settings.singleTestTime;
  this.instance = instance;
}
 
Example 2
Source File: LogFilter.java    From scaffold with Apache License 2.0 5 votes vote down vote up
@Override
public Response afterReceiveRequest(Invocation invocation, HttpServletRequestEx httpServletRequestEx) {
  String userName = invocation.getContext().get(AuthenticationFilter.EDGE_AUTHENTICATION_NAME);
  if (StringUtils.isNotEmpty(userName)) {
    HttpEntity<LogDTO> request = new HttpEntity<>(
        new LogDTO(userName, invocation.getMicroserviceName(), invocation.getOperationName(), new Date()));
    try {
      restTemplate.postForEntity("cse://" + LOG_SERVICE_NAME + "/record", request, Boolean.class);
    } catch (Exception ignored) {
    }
  }
  return null;
}
 
Example 3
Source File: FaultInjectionUtil.java    From servicecomb-java-chassis with Apache License 2.0 5 votes vote down vote up
/**
 * Handles the reading fault injection configuration.
 *
 * @param invocation
 *            invocation of request
 * @param key
 *            configuration key
 * @return configuration value
 */
public static int getFaultInjectionConfig(Invocation invocation, String key) {
  int value = 0;
  String config;

  // get the config base on priority. operationName-->schema-->service-->global
  String operationName = invocation.getOperationName();
  String schema = invocation.getSchemaId();
  String serviceName = invocation.getMicroserviceName();

  config = CONSUMER_FAULTINJECTION + serviceName + ".schemas." + schema + ".operations." + operationName + "."
      + CONSUMER_FAULTINJECTION_POLICY_PROTOCOLS + invocation.getTransport().getName() + "." + key;

  value = getConfigValue(config);
  if ((value != FAULT_INJECTION_DEFAULT_VALUE)) {
    return value;
  }

  config = CONSUMER_FAULTINJECTION + serviceName + ".schemas." + schema + "."
      + CONSUMER_FAULTINJECTION_POLICY_PROTOCOLS + invocation.getTransport().getName() + "." + key;

  value = getConfigValue(config);
  if ((value != FAULT_INJECTION_DEFAULT_VALUE)) {
    return value;
  }

  config = CONSUMER_FAULTINJECTION + serviceName + "." + CONSUMER_FAULTINJECTION_POLICY_PROTOCOLS
      + invocation.getTransport().getName() + "." + key;
  value = getConfigValue(config);
  if ((value != FAULT_INJECTION_DEFAULT_VALUE)) {
    return value;
  }

  config = CONSUMER_FAULTINJECTION_GLOBAL + CONSUMER_FAULTINJECTION_POLICY_PROTOCOLS
      + invocation.getTransport().getName() + "." + key;

  value = getConfigValue(config);
  return value;
}
 
Example 4
Source File: RouterServerListFilter.java    From servicecomb-java-chassis with Apache License 2.0 5 votes vote down vote up
@Override
public List<ServiceCombServer> getFilteredListOfServers(List<ServiceCombServer> list,
    Invocation invocation) {
  String targetServiceName = invocation.getMicroserviceName();
  Map<String, String> headers = addHeaders(invocation);
  headers = filterHeaders(headers);
  return RouterFilter
      .getFilteredListOfServers(list, targetServiceName, headers,
          distributer);
}
 
Example 5
Source File: TestConfiguration.java    From servicecomb-java-chassis with Apache License 2.0 5 votes vote down vote up
@Test
public void testConfiguration() {

  assertNotNull(Configuration.INSTANCE);
  assertEquals("returnnull", Configuration.FALLBACKPOLICY_POLICY_RETURN);
  assertEquals("throwexception", Configuration.FALLBACKPOLICY_POLICY_THROW);

  Configuration c = Configuration.INSTANCE;
  Invocation invocation = Mockito.mock(Invocation.class);
  String test2 = invocation.getMicroserviceName();

  Mockito.when(invocation.getOperationMeta()).thenReturn(Mockito.mock(OperationMeta.class));
  Mockito.when(invocation.getOperationMeta().getMicroserviceName()).thenReturn("testqualify");

  int res = c.getIsolationTimeoutInMilliseconds("groupname", test2, "testqualify");
  assertEquals(30000, res);
  boolean b1 = c.getIsolationTimeoutEnabled("groupname", test2, "testqualify");
  assertFalse(b1);
  int res1 = c.getIsolationMaxConcurrentRequests("groupname", test2, "testqualify");
  assertEquals(1000, res1);
  boolean b2 = c.isCircuitBreakerEnabled("groupname", test2, "testqualify");
  assertTrue(b2);
  String str = c.getFallbackPolicyPolicy("groupname", test2, "testqualify");
  // no need to give default value now
  assertEquals(null, str);

  assertFalse(c.isCircuitBreakerForceOpen("groupname", test2, "testqualify"));
  assertFalse(c.isCircuitBreakerForceClosed("groupname", test2, "testqualify"));
  assertEquals(15000, c.getCircuitBreakerSleepWindowInMilliseconds("groupname", test2, "testqualify"));
  assertEquals(20, c.getCircuitBreakerRequestVolumeThreshold("groupname", test2, "testqualify"));
  assertEquals(50, c.getCircuitBreakerErrorThresholdPercentage("groupname", test2, "testqualify"));
  assertTrue(c.isFallbackEnabled("groupname", test2, "testqualify"));
}