helidon-io / helidon

Java libraries for writing microservices
https://helidon.io
Apache License 2.0
3.49k stars 562 forks source link

helidon-integrations-cdi-oci-objectstorage (bucket objects crud exceptions) #3580

Closed btcdevops-apps closed 2 years ago

btcdevops-apps commented 2 years ago

Environment Details


Problem Description - helidon-integrations-cdi-oci-objectstorage (bucket crud exceptions)

unable to interact with objectstorage - bucket. I am trying to upload files into an oci bucket in my tenancy. I have configured the application.yaml file

oci: objectstorage: namespace: ${tenancy.namespace} namespaceName: ${tenancy.namespace} region: ${tenancy.region} bucket: ${app.cerpsys.endvi.cloud.bucket} compartment: ${bucket.compartment.ocid} auth: fingerprint: ${user.pem.fingerprint} keyFile: ${user.pem.key.path} passphraseCharacters: ${user.pem.key.passphrase} user: ${user.ocid} tenancy: ${tenancy.ocid} compartment: ${bucket.compartment.ocid} user: ${user.ocid} fingerprint: ${user.pem.fingerprint} tenancy: ${tenancy.ocid} region: ${tenancy.region} key-pem: ${user.pem.key.path} passphraseCharacters: ${user.pem.key.passphrase} compartment: ${bucket.compartment.ocid}

Exceptions Encountered vary depending on code snippet as below:

  1. `com.oracle.bmc.model.BmcException: (401, Unknown, false) Detailed exception information not available (opc-request-id: lhr-1:h85rkflxTcu-tfH6foCqgidpbnXbqGoey_Mbj1v5o1b-6ZTRTHCzG9a6xeumCf) at com.oracle.bmc.http.internal.ResponseHelper.throwIfNotSuccessful(ResponseHelper.java:128) at com.oracle.bmc.http.internal.ResponseConversionFunctionFactory$ValidatingParseResponseFunction.apply(ResponseConversionFunctionFactory.java:88) -----------------------------snippet below--------- //@Inject ObjectStorage ociTenancyObjectStorage; String objectName = payload.getStorageURL(); System.out.println(objectName);

        UploadManager uploadManager = new UploadManager(ociTenancyObjectStorage, getUploadConfiguration());
    
        PutObjectRequest request = PutObjectRequest.builder()
                .bucketName(ociBucketName)
                .namespaceName(ociTenancyNamespace)
                .contentType("application/vnd.ms-excel")
                .objectName(objectName)
                .build();
    
        UploadManager.UploadRequest uploadRequest = UploadManager
                .UploadRequest
                .builder(MultiPartFileUtility.FileManager.getFile(payload.getOptionalDiscPath().get()))
                .allowOverwrite(true)
                .build(request);
    
        UploadManager.UploadResponse uploadResponse = uploadManager.upload(uploadRequest);

``

  1. java.util.concurrent.CompletionException: io.helidon.webclient.WebClientException: Connection reset by the host at java.base/java.util.concurrent.CompletableFuture.encodeRelay(CompletableFuture.java:367) at java.base/java.util.concurrent.CompletableFuture.completeRelay(CompletableFuture.java:376) at java.base/java.util.concurrent.CompletableFuture$UniRelay.tryFire(CompletableFuture.java:1019) --------------------------------------snippet below-------------------------------------------

        //@Inject OciObjectStorage ociTenancyObjectStorage
        PutObject.Response response = ociTenancyObjectStorage.putObject(
                PutObject.Request.builder()
                        .contentLength(contentLength)
                        .bucket(ociBucketName)
                        .requestMediaType(fileMediaType)
                        .objectName(payload.getStorageURL()),
                Channels.newChannel(fileInputStream)
        );
  2. com.oracle.bmc.model.BmcException: (401, Unknown, false) Detailed exception information not available (opc-request-id: lhr-1:xNJN_MPIF38c701Blzb1yyK3tShdcb77FLqSO5Nu8DiAtDq8x9xrnZaRs1rtD--B) at com.oracle.bmc.http.internal.ResponseHelper.throwIfNotSuccessful(ResponseHelper.java:128) at com.oracle.bmc.http.internal.ResponseConversionFunctionFactory$ValidatingParseResponseFunction.apply(ResponseConversionFunctionFactory.java:88) at ------------------snippet below----------------

    //@Inject ObjectStorage ociTenancyObjectStorage; UploadManager uploadManager = new UploadManager(ociTenancyObjectStorage,getUploadConfiguration()); PutObjectRequest putObjectRequest = PutObjectRequest.builder() .bucketName(ociBucketName) .namespaceName(ociTenancyNamespace) .contentType(payload.getFileMimeType()) .objectName(objectName) .build(); UploadManager.UploadRequest request = UploadManager.UploadRequest .builder(MultiPartFileUtility.FileManager.getFile(payload.getOptionalDiscPath().get())) .allowOverwrite(true) .build(putObjectRequest); UploadManager.UploadResponse response = uploadManager.upload(request); `

    Steps to reproduce

spericas commented 2 years ago

@btcdevops-apps Options (1) and (3) are not using Helidon APIs. As for (2), have you followed the structure of this test?

https://github.com/oracle/helidon/tree/master/examples/integrations/oci/objectstorage-cdi

Note that there's two files application.yaml and ~/helidon/conf/examples.yaml from which configuration is read. See ObjectStorageCdiMain. This is used to separate common from user-specific config ---the Yaml config that you included in this issue isn't formatted properly, so it's hard to provide feedback based on it.

btcdevops-apps commented 2 years ago

@spericas thanks for the quick response. please see below for the yaml structure I'm using. Note: the helidon/conf/examples.yaml file used in ObjectStorageCdiMain is not available in the repository master so I'm unable to verify mine matches.

snippet.yaml.txt

spericas commented 2 years ago

@spericas thanks for the quick response. please see below for the yaml structure I'm using. Note: the helidon/conf/examples.yaml file used in ObjectStorageCdiMain is not available in the repository master so I'm unable to verify mine matches.

snippet.yaml.txt

https://github.com/oracle/helidon/blob/master/examples/integrations/oci/objectstorage-cdi/src/main/java/io/helidon/examples/integrations/oci/objectstorage/cdi/ObjectStorageCdiMain.java

Please make sure to study the example and the docs (https://helidon.io/docs/v2/#/mp/oci/02_object-storage) to understand how to use the Helidon API.

btcdevops-apps commented 2 years ago

Thanks @spericas I eventually had to construct my objects manually following this example .

The helidon mp example currently seems to require the oci config in directory .oci which really seems questionable for a containerized application that should not really have a dependency on oci cli tool.

Hence the example I followed allows me to put the config file anywhere such as class path and load it at runtime.

This will make it easier for me to change the content using oke configmaps/secrets @ deployment time.

Your input was very useful and gave me insights i needed.