Skip to content

Commit 2344f63

Browse files
authored
Revert "fix: Improve Circuit breaker behaviour (#1017)" (#1040)
1 parent d0175e2 commit 2344f63

File tree

5 files changed

+7
-95
lines changed

5 files changed

+7
-95
lines changed

cloudplatform/connectivity-destination-service/src/main/java/com/sap/cloud/sdk/cloudplatform/connectivity/DestinationService.java

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,6 @@ static ResilienceConfiguration createResilienceConfiguration(
120120
Try<Destination>
121121
tryGetDestination( @Nonnull final String destinationName, @Nonnull final DestinationOptions options )
122122
{
123-
if( Cache.preLookupCheckEnabled && !preLookupCheckSuccessful(destinationName) ) {
124-
final String msg = "Destination %s was not found among the destinations of the current tenant.";
125-
return Try.failure(new DestinationNotFoundException(String.format(msg, destinationName)));
126-
}
127123
return Cache.getOrComputeDestination(this, destinationName, options, this::loadAndParseDestination);
128124
}
129125

@@ -388,13 +384,6 @@ private static boolean hasCauseAssignableFrom( @Nonnull final Throwable t, @Nonn
388384
return ExceptionUtils.getThrowableList(t).stream().map(Throwable::getClass).anyMatch(cls::isAssignableFrom);
389385
}
390386

391-
private boolean preLookupCheckSuccessful( final String destinationName )
392-
{
393-
return getAllDestinationProperties()
394-
.stream()
395-
.anyMatch(properties -> properties.get(DestinationProperty.NAME).contains(destinationName));
396-
}
397-
398387
/**
399388
* Helper class that encapsulates all caching related configuration options.
400389
*
@@ -437,7 +426,6 @@ public static final class Cache
437426

438427
private static boolean cacheEnabled = true;
439428
private static boolean changeDetectionEnabled = true;
440-
private static boolean preLookupCheckEnabled = true;
441429

442430
static {
443431
recreateSingleCache();
@@ -455,18 +443,6 @@ static boolean isChangeDetectionEnabled()
455443
return changeDetectionEnabled;
456444
}
457445

458-
/**
459-
* Disables checking if a destination exists before trying to call it directly when invoking
460-
* {@link #tryGetDestination}. All available destinations can be found with
461-
* {@link #getAllDestinationProperties}.
462-
*
463-
* @since 5.25.0
464-
*/
465-
public static void disablePreLookupCheck()
466-
{
467-
preLookupCheckEnabled = false;
468-
}
469-
470446
@Nonnull
471447
static com.github.benmanes.caffeine.cache.Cache<CacheKey, Destination> instanceSingle()
472448
{
@@ -520,7 +496,6 @@ static void reset()
520496
cacheEnabled = true;
521497
}
522498
changeDetectionEnabled = true;
523-
preLookupCheckEnabled = true;
524499

525500
sizeLimit = Option.some(DEFAULT_SIZE_LIMIT);
526501
expirationDuration = Option.some(DEFAULT_EXPIRATION_DURATION);

cloudplatform/connectivity-destination-service/src/test/java/com/sap/cloud/sdk/cloudplatform/connectivity/DestinationServiceAuthenticationTest.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,6 @@ void setMockAdapter()
6666
.when(mockAdapter)
6767
.getConfigurationAsJson(anyString(), any());
6868
sut = new DestinationService(mockAdapter);
69-
// Disable PreLookupCheck to simplify test setup
70-
DestinationService.Cache.disablePreLookupCheck();
7169
}
7270

7371
@Test
@@ -292,7 +290,7 @@ void testOAuth2PasswordWithoutUserToken()
292290
assertThat(dest.asHttp().getHeaders())
293291
.containsExactlyInAnyOrder(new Header("Authorization", "Bearer " + oAuthToken));
294292

295-
verify(mockAdapter, times(1)).getConfigurationAsJson(eq(SERVICE_PATH_DESTINATION), eq(expectedStrategy));
293+
verify(mockAdapter, times(1)).getConfigurationAsJson(anyString(), eq(expectedStrategy));
296294
verifyNoMoreInteractions(mockAdapter);
297295
}
298296

@@ -384,7 +382,7 @@ void testSAPAssertionSSO()
384382
assertThat(dest.asHttp().getAuthenticationType()).isEqualTo(AuthenticationType.SAP_ASSERTION_SSO);
385383
assertThat(dest.asHttp().getHeaders()).containsExactlyInAnyOrder(new Header("Cookie", assertionCookie));
386384

387-
verify(mockAdapter, times(1)).getConfigurationAsJson(eq(SERVICE_PATH_DESTINATION), eq(expectedStrategy));
385+
verify(mockAdapter, times(1)).getConfigurationAsJson(anyString(), eq(expectedStrategy));
388386
verifyNoMoreInteractions(mockAdapter);
389387
}
390388

cloudplatform/connectivity-destination-service/src/test/java/com/sap/cloud/sdk/cloudplatform/connectivity/DestinationServicePrincipalPropagationTest.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,6 @@ void setupConnectivity( @Nonnull final WireMockRuntimeInfo wm )
108108
.withRequestBody(
109109
equalTo("grant_type=client_credentials&client_secret=CLIENT_SECRET&client_id=CLIENT_ID"))
110110
.willReturn(okJson("{\"access_token\":\"provider-client-credentials\",\"expires_in\":3600}")));
111-
// Disable PreLookupCheck to simplify test setup
112-
DestinationService.Cache.disablePreLookupCheck();
113111
}
114112

115113
@AfterEach

cloudplatform/connectivity-destination-service/src/test/java/com/sap/cloud/sdk/cloudplatform/connectivity/DestinationServiceTest.java

Lines changed: 5 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -113,15 +113,6 @@ class DestinationServiceTest
113113
"ProxyType": "Internet",
114114
"KeyStorePassword": "password",
115115
"KeyStoreLocation": "aaa"
116-
},
117-
{
118-
"Name": "SomeDestinationName",
119-
"Type": "HTTP",
120-
"URL": "https://a.s4hana.ondemand.com",
121-
"Authentication": "ClientCertificateAuthentication",
122-
"ProxyType": "Internet",
123-
"KeyStorePassword": "password",
124-
"KeyStoreLocation": "aaa"
125116
}]
126117
""";
127118

@@ -345,9 +336,6 @@ class DestinationServiceTest
345336
@BeforeEach
346337
void setup()
347338
{
348-
// Disable PreLookupCheck to simplify test setup
349-
DestinationService.Cache.disablePreLookupCheck();
350-
351339
providerTenant = new DefaultTenant("provider-tenant");
352340
subscriberTenant = new DefaultTenant("subscriber-tenant");
353341
context.setTenant(subscriberTenant);
@@ -454,7 +442,7 @@ void testGettingDestinationProperties()
454442

455443
assertThat(destinationList)
456444
.extracting(d -> d.get(DestinationProperty.NAME).get())
457-
.containsExactly("CC8-HTTP-BASIC", "CC8-HTTP-CERT1", "CC8-HTTP-CERT", destinationName);
445+
.containsExactly("CC8-HTTP-BASIC", "CC8-HTTP-CERT1", "CC8-HTTP-CERT");
458446

459447
final DestinationProperties destination =
460448
destinationList
@@ -490,7 +478,7 @@ void testGettingDestinationPropertiesProvider()
490478
final Collection<DestinationProperties> destinationList = loader.getAllDestinationProperties(ALWAYS_PROVIDER);
491479
assertThat(destinationList)
492480
.extracting(d -> d.get(DestinationProperty.NAME).get())
493-
.containsExactly("CC8-HTTP-BASIC", "CC8-HTTP-CERT1", "CC8-HTTP-CERT", destinationName);
481+
.containsExactly("CC8-HTTP-BASIC", "CC8-HTTP-CERT1", "CC8-HTTP-CERT");
494482
}
495483

496484
@Test
@@ -506,7 +494,7 @@ void testGettingDestinationPropertiesSubscriber()
506494
final Collection<DestinationProperties> destinationList = loader.getAllDestinationProperties(ONLY_SUBSCRIBER);
507495
assertThat(destinationList)
508496
.extracting(d -> d.get(DestinationProperty.NAME).get())
509-
.containsExactly("CC8-HTTP-BASIC", "CC8-HTTP-CERT1", "CC8-HTTP-CERT", destinationName);
497+
.containsExactly("CC8-HTTP-BASIC", "CC8-HTTP-CERT1", "CC8-HTTP-CERT");
510498
}
511499

512500
@Test
@@ -601,10 +589,10 @@ void testGetAllDestinationsForProvider()
601589
final List<Destination> destinationList = new ArrayList<>();
602590
destinations.get().forEach(destinationList::add);
603591

604-
assertThat(destinationList.size()).isEqualTo(4);
592+
assertThat(destinationList.size()).isEqualTo(3);
605593
assertThat(destinationList)
606594
.extracting(d -> d.get(DestinationProperty.NAME).get())
607-
.containsOnly("CC8-HTTP-BASIC", "CC8-HTTP-CERT", "CC8-HTTP-CERT1", destinationName);
595+
.containsOnly("CC8-HTTP-BASIC", "CC8-HTTP-CERT", "CC8-HTTP-CERT1");
608596
}
609597

610598
@SuppressWarnings( "deprecation" )
@@ -1922,49 +1910,4 @@ private String createHttpDestinationServiceResponse( final String name, final St
19221910
}
19231911
""", name, url);
19241912
}
1925-
1926-
@Test
1927-
void testPrependGetAllDestinationsCall()
1928-
{
1929-
// Reset Cache to re-enable the PreLookupCheck
1930-
DestinationService.Cache.reset();
1931-
1932-
doReturn(responseServiceInstanceDestination)
1933-
.when(destinationServiceAdapter)
1934-
.getConfigurationAsJson(eq("/v1/instanceDestinations"), any());
1935-
doReturn(responseSubaccountDestination)
1936-
.when(destinationServiceAdapter)
1937-
.getConfigurationAsJson(eq("/v1/subaccountDestinations"), any());
1938-
1939-
Destination result = loader.tryGetDestination(destinationName).get();
1940-
1941-
verify(destinationServiceAdapter, times(1)).getConfigurationAsJson(eq("/v1/instanceDestinations"), any());
1942-
verify(destinationServiceAdapter, times(1)).getConfigurationAsJson(eq("/v1/subaccountDestinations"), any());
1943-
verify(destinationServiceAdapter, times(1))
1944-
.getConfigurationAsJson(eq("/v1/destinations/" + destinationName), any());
1945-
verifyNoMoreInteractions(destinationServiceAdapter);
1946-
}
1947-
1948-
@Test
1949-
void testPrependGetAllDestinationsCallWithMissingDestination()
1950-
{
1951-
// Reset Cache to re-enable the PreLookupCheck
1952-
DestinationService.Cache.reset();
1953-
1954-
doReturn(responseServiceInstanceDestination)
1955-
.when(destinationServiceAdapter)
1956-
.getConfigurationAsJson(eq("/v1/instanceDestinations"), any());
1957-
doReturn(responseSubaccountDestination)
1958-
.when(destinationServiceAdapter)
1959-
.getConfigurationAsJson(eq("/v1/subaccountDestinations"), any());
1960-
1961-
assertThatThrownBy(() -> loader.tryGetDestination("thisDestinationDoesNotExist").get())
1962-
.isInstanceOf(DestinationNotFoundException.class)
1963-
.hasMessageContaining("was not found among the destinations of the current tenant.");
1964-
1965-
verify(destinationServiceAdapter, times(1)).getConfigurationAsJson(eq("/v1/instanceDestinations"), any());
1966-
verify(destinationServiceAdapter, times(1)).getConfigurationAsJson(eq("/v1/subaccountDestinations"), any());
1967-
verifyNoMoreInteractions(destinationServiceAdapter);
1968-
1969-
}
19701913
}

release_notes.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212

1313
### ✨ New Functionality
1414

15-
- `DestinationService.tryGetDestination` now checks if the given destination exists before trying to call it directly.
16-
This behaviour is enabled by default and can be disabled via `DestinationService.Cache.disablePreLookupCheck`.
1715
- Added native DestinationLoader implementation through the `TransparentProxy` class. This enables seamless destination
1816
retrieval via `tryGetDestination` and provides full Cloud SDK integration for applications running in Kubernetes
1917
environments where Transparent Proxy is available.

0 commit comments

Comments
 (0)