Skip to content

Commit

Permalink
Merge branch '4.3.x' into 4.4.x
Browse files Browse the repository at this point in the history
  • Loading branch information
sdelamo committed Dec 13, 2024
2 parents 7aef9b2 + c858304 commit 528d7ee
Show file tree
Hide file tree
Showing 8 changed files with 105 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import com.oracle.bmc.ClientConfiguration;
import com.oracle.bmc.auth.AbstractAuthenticationDetailsProvider;
import com.oracle.bmc.auth.RegionProvider;
import com.oracle.bmc.common.ClientBuilderBase;
import com.oracle.bmc.http.ClientConfigurator;
import com.oracle.bmc.http.client.HttpProvider;
Expand All @@ -33,6 +34,7 @@
* @param <B> The builder type
* @param <T> The client type
*/
@Internal
public abstract class AbstractSdkClientFactory<B extends ClientBuilderBase<B, T>, T> {
private final B builder;

Expand Down Expand Up @@ -71,12 +73,14 @@ protected AbstractSdkClientFactory(
*
* @param clientBuilder The builder for client
* @param authenticationDetailsProvider The authentication details provider
* @param regionProvider The region provider
* @return The client to build
*/
protected abstract @NonNull T build(
@NonNull B clientBuilder,
@NonNull AbstractAuthenticationDetailsProvider authenticationDetailsProvider
);
@NonNull AbstractAuthenticationDetailsProvider authenticationDetailsProvider,
@NonNull RegionProvider regionProvider
);

/**
* Set the HTTP provider for this client. This is injected by the application context, in order
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
package io.micronaut.oraclecloud.factory;
package io.micronaut.oraclecloud.factory

import com.oracle.bmc.Region
import com.oracle.bmc.auth.RegionProvider;
import com.oracle.bmc.objectstorage.ObjectStorageAsyncClient
import com.oracle.bmc.objectstorage.ObjectStorageClient
import io.micronaut.context.annotation.BootstrapContextCompatible
import io.micronaut.context.annotation.Primary
import io.micronaut.context.annotation.Property
import io.micronaut.context.annotation.Replaces
import io.micronaut.context.annotation.Requires
import io.micronaut.context.event.BeanCreatedEvent
import io.micronaut.context.event.BeanCreatedEventListener
import io.micronaut.core.annotation.NonNull
Expand All @@ -10,7 +17,7 @@ import jakarta.inject.Inject
import jakarta.inject.Singleton
import spock.lang.Specification


@Property(name = "spec.name", value = "ObjectStorageFactorySpec")
@MicronautTest
class ObjectStorageFactorySpec extends Specification {

Expand Down Expand Up @@ -41,6 +48,7 @@ class ObjectStorageFactorySpec extends Specification {
asyncClient.endpoint == ASYNC_ENDPOINT
}

@Requires(property = "spec.name", value = "ObjectStorageFactorySpec")
@Singleton
static class DatabaseClientBuilderListener
implements BeanCreatedEventListener<ObjectStorageClient.Builder> {
Expand All @@ -54,6 +62,7 @@ class ObjectStorageFactorySpec extends Specification {
}
}

@Requires(property = "spec.name", value = "ObjectStorageFactorySpec")
@Singleton
static class DatabaseAsyncClientBuilderListener
implements BeanCreatedEventListener<ObjectStorageAsyncClient.Builder> {
Expand All @@ -67,4 +76,16 @@ class ObjectStorageFactorySpec extends Specification {
}
}

@Requires(property = "spec.name", value = "ObjectStorageFactorySpec")
@Singleton
@BootstrapContextCompatible
@Replaces(RegionProvider.class)
static class RegionProviderReplacement implements RegionProvider {

@Override
Region getRegion() {
return null
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@

import com.oracle.bmc.http.client.HttpProvider;
import io.micronaut.context.ApplicationContext;
import io.micronaut.core.util.StringUtils;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.DisabledIfEnvironmentVariable;

public class NettyManagedTest extends NettyUnmanagedTest {
ApplicationContext ctx;
Expand All @@ -22,4 +25,11 @@ public void tearDown() {
HttpProvider provider() {
return ctx.getBean(HttpProvider.class);
}

@DisabledIfEnvironmentVariable(named = "CI", matches = StringUtils.TRUE,
disabledReason = "It is flaky https://ge.micronaut.io/scans/tests?tests.container=io.micronaut.oraclecloud.httpclient.netty.NettyManagedTest&tests.test=connectionReuse()")
@Test
public void connectionReuse() throws Exception {
super.connectionReuse();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ Stream<MetricDataDetails> trackRawData(Meter meter) {
if (meter instanceof OracleCloudDatapointProducer oracleCloudDatapointProducer) {
return Stream.of(metricDataDetails(meter.getId(), null, oracleCloudDatapointProducer.getDatapoints()));
}
logger.error("Metrics name: {}. Haven't publish metrics for class: {}",meter.getId(), meter.getClass());
logger.error("Metrics name: {}. Haven't publish metrics for class: {}", meter.getId(), meter.getClass());
return Stream.empty();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package io.micronaut.oraclecloud.monitoring.sdk

import com.oracle.bmc.Region
import com.oracle.bmc.auth.AbstractAuthenticationDetailsProvider
import com.oracle.bmc.monitoring.Monitoring
import com.oracle.bmc.monitoring.MonitoringClient
import io.micronaut.context.annotation.Property
import io.micronaut.context.annotation.Requires
import io.micronaut.test.extensions.spock.annotation.MicronautTest
import jakarta.inject.Inject
import org.junit.jupiter.api.Assertions
import spock.lang.Specification

@MicronautTest(startApplication = false)
@Property(name = "spec.name", value = "MonitorRegionProviderSpec")
@Property(name = "micronaut.metrics.export.oraclecloud.enabled", value = "false")
@Property(name = "oci.vault.config.enabled", value = "false")
@Property(name = "micronaut.config-client.enabled", value = "false")
@Property(name = "datasources.enabled", value = "false")
@Requires(bean = AbstractAuthenticationDetailsProvider.class)
class MonitorRegionProviderSpec extends Specification {

@Inject
Monitoring monitoring

void 'test the' () {
when:
String endpoint = monitoring.getEndpoint()

then:
Region.EU_JOVANOVAC_1.getEndpoint(MonitoringClient.SERVICE).get() == endpoint
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package io.micronaut.oraclecloud.monitoring.sdk;

import com.oracle.bmc.Region;
import com.oracle.bmc.auth.RegionProvider;
import io.micronaut.context.annotation.BootstrapContextCompatible;
import io.micronaut.context.annotation.Primary;
import io.micronaut.context.annotation.Property;
import io.micronaut.context.annotation.Replaces;
import io.micronaut.context.annotation.Requires;
import jakarta.inject.Singleton;

@Replaces(RegionProvider.class)
@BootstrapContextCompatible
@Singleton
@Requires(property = "spec.name", value = "MonitorRegionProviderSpec")
public class VaultRegionProviderMock implements RegionProvider {
@Override
public Region getRegion() {
return Region.EU_JOVANOVAC_1;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ public class OracleCloudSdkProcessor extends AbstractProcessor {
* Processing environment option used to specify the client classes to process.
*/
public static final String OCI_SDK_CLIENT_CLASSES_OPTION = "ociSdkClientClasses";

private static final String RETURN_BUILDER_STATEMENT_WITH_REGION = "return regionProvider.getRegion() != null ? clientBuilder.region(regionProvider.getRegion()).build(authenticationDetailsProvider) : clientBuilder.build(authenticationDetailsProvider)";
private static final String RETURN_BUILDER_STATEMENT_WITHOUT_REGION = "return clientBuilder.build(authenticationDetailsProvider)";
private static final List<String> FACTORIES_THAT_DOESNT_SUPPORT_REGION = List.of("KmsCrypto", "KmsManagement", "IdentityDomains", "Stream");

private Filer filer;
private Messager messager;
private Elements elements;
Expand Down Expand Up @@ -353,11 +358,13 @@ private String writeClientFactory(Element e, String packageName, String simpleNa
final String factoryName = simpleName + "Factory";
final String factoryPackageName = packageName.replace("com.oracle.bmc", CLIENT_PACKAGE);
final TypeSpec.Builder builder = defineSuperclass(packageName, simpleName, factoryName);

final MethodSpec.Builder constructor = buildConstructor(simpleName, builder);
ClassName builderType = getBuilderClassNameForClient(packageName, simpleName);
builder.addField(FieldSpec.builder(builderType, "builder", Modifier.PRIVATE).build());
builder.addAnnotation(Factory.class);
final ClassName authProviderType = ClassName.get("com.oracle.bmc.auth", "AbstractAuthenticationDetailsProvider");
final ClassName regionProvider = ClassName.get("com.oracle.bmc.auth", "RegionProvider");
final AnnotationSpec.Builder requiresSpec = AnnotationSpec.builder(Requires.class)
.addMember("classes", simpleName + ".class")
.addMember("beans", authProviderType.canonicalName() + ".class");
Expand Down Expand Up @@ -389,11 +396,12 @@ private String writeClientFactory(Element e, String packageName, String simpleNa
buildMethod.returns(ClassName.get(packageName, simpleName))
.addParameter(builderType, "clientBuilder")
.addParameter(authProviderType, "authenticationDetailsProvider")
.addAnnotation(Singleton.class)
.addParameter(regionProvider, "regionProvider")
.addAnnotation(Singleton.class)
.addAnnotation(requiresSpec.build())
.addAnnotation(preDestroy.build())
.addModifiers(Modifier.PROTECTED)
.addCode("return clientBuilder.build(authenticationDetailsProvider);");
.addStatement(FACTORIES_THAT_DOESNT_SUPPORT_REGION.stream().noneMatch(factoryName::startsWith) ? RETURN_BUILDER_STATEMENT_WITH_REGION : RETURN_BUILDER_STATEMENT_WITHOUT_REGION);
if (isBootstrapCompatible) {
buildMethod.addAnnotation(BootstrapContextCompatible.class);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import io.micronaut.context.annotation.BootstrapContextCompatible;
import io.micronaut.context.annotation.ConfigurationProperties;
import io.micronaut.context.annotation.EachProperty;
import io.micronaut.context.annotation.Property;
import io.micronaut.core.annotation.NonNull;
import io.micronaut.core.util.StringUtils;
import io.micronaut.discovery.config.ConfigDiscoveryConfiguration;
Expand Down

0 comments on commit 528d7ee

Please sign in to comment.