This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push:
new 5ededc3 CAMEL-16758: Add Huawei Cloud OBS operation (#5799)
5ededc3 is described below
commit 5ededc3186cfeab3698181495b8dcf3520182c93
Author: Hokutor <[email protected]>
AuthorDate: Tue Jul 6 12:55:40 2021 -0400
CAMEL-16758: Add Huawei Cloud OBS operation (#5799)
---
.../src/main/docs/hwcloud-obs-component.adoc | 1 +
.../component/huaweicloud/obs/OBSProducer.java | 23 +++++++
.../huaweicloud/obs/constants/OBSOperations.java | 1 +
.../obs/BucketMetadataFunctionalTest.java | 71 ++++++++++++++++++++
.../huaweicloud/obs/BucketMetadataTest.java | 77 ++++++++++++++++++++++
.../obs/constants/OBSOperationsTest.java | 1 +
6 files changed, 174 insertions(+)
diff --git
a/components/camel-huawei/camel-huaweicloud-obs/src/main/docs/hwcloud-obs-component.adoc
b/components/camel-huawei/camel-huaweicloud-obs/src/main/docs/hwcloud-obs-component.adoc
index 7f653d0..646111d 100644
---
a/components/camel-huawei/camel-huaweicloud-obs/src/main/docs/hwcloud-obs-component.adoc
+++
b/components/camel-huawei/camel-huaweicloud-obs/src/main/docs/hwcloud-obs-component.adoc
@@ -131,6 +131,7 @@ If any of the above properties are set, they will override
their corresponding q
- createBucket - `bucketName` parameter is *required*, `bucketLocation`
parameter is optional
- deleteBucket - `bucketName` parameter is *required*
- checkBucketExists - `bucketName` parameter is *required*
+- getBucketMetadata - `bucketName` parameter is *required*
== Using ServiceKey Configuration Bean
diff --git
a/components/camel-huawei/camel-huaweicloud-obs/src/main/java/org/apache/camel/component/huaweicloud/obs/OBSProducer.java
b/components/camel-huawei/camel-huaweicloud-obs/src/main/java/org/apache/camel/component/huaweicloud/obs/OBSProducer.java
index dfd4a76..477d9ee 100644
---
a/components/camel-huawei/camel-huaweicloud-obs/src/main/java/org/apache/camel/component/huaweicloud/obs/OBSProducer.java
+++
b/components/camel-huawei/camel-huaweicloud-obs/src/main/java/org/apache/camel/component/huaweicloud/obs/OBSProducer.java
@@ -21,6 +21,8 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.gson.Gson;
import com.obs.services.ObsClient;
import com.obs.services.exception.ObsException;
+import com.obs.services.model.BucketMetadataInfoRequest;
+import com.obs.services.model.BucketMetadataInfoResult;
import com.obs.services.model.CreateBucketRequest;
import com.obs.services.model.HeaderResponse;
import com.obs.services.model.ListBucketsRequest;
@@ -73,6 +75,9 @@ public class OBSProducer extends DefaultProducer {
case OBSOperations.CHECK_BUCKET_EXISTS:
checkBucketExists(exchange);
break;
+ case OBSOperations.GET_BUCKET_METADATA:
+ getBucketMetadata(exchange);
+ break;
default:
throw new UnsupportedOperationException(
String.format("%s is not a supported operation",
clientConfigurations.getOperation()));
@@ -172,6 +177,24 @@ public class OBSProducer extends DefaultProducer {
}
/**
+ * Perform get bucket metadata operation
+ *
+ * @param exchange
+ */
+ private void getBucketMetadata(Exchange exchange) throws ObsException {
+ // check for bucket name, which is mandatory to get bucket metadata
+ if (ObjectHelper.isEmpty(clientConfigurations.getBucketName())) {
+ LOG.error("No bucket name given");
+ throw new IllegalArgumentException("Bucket name is mandatory to
get bucket metadata");
+ }
+
+ // invoke get bucket metadata method and map response object to
exchange body
+ BucketMetadataInfoRequest request = new
BucketMetadataInfoRequest(clientConfigurations.getBucketName());
+ BucketMetadataInfoResult response =
obsClient.getBucketMetadata(request);
+ exchange.getMessage().setBody(gson.toJson(response));
+ }
+
+ /**
* Update dynamic client configurations. Some endpoint parameters
(operation, and bucket name and location) can also
* be passed via exchange properties, so they can be updated between each
transaction. Since they can change, we
* must clear the previous transaction and update these parameters with
their new values
diff --git
a/components/camel-huawei/camel-huaweicloud-obs/src/main/java/org/apache/camel/component/huaweicloud/obs/constants/OBSOperations.java
b/components/camel-huawei/camel-huaweicloud-obs/src/main/java/org/apache/camel/component/huaweicloud/obs/constants/OBSOperations.java
index 423eff5..dee4001 100644
---
a/components/camel-huawei/camel-huaweicloud-obs/src/main/java/org/apache/camel/component/huaweicloud/obs/constants/OBSOperations.java
+++
b/components/camel-huawei/camel-huaweicloud-obs/src/main/java/org/apache/camel/component/huaweicloud/obs/constants/OBSOperations.java
@@ -24,6 +24,7 @@ public final class OBSOperations {
public static final String CREATE_BUCKET = "createBucket";
public static final String DELETE_BUCKET = "deleteBucket";
public static final String CHECK_BUCKET_EXISTS = "checkBucketExists";
+ public static final String GET_BUCKET_METADATA = "getBucketMetadata";
private OBSOperations() {
}
diff --git
a/components/camel-huawei/camel-huaweicloud-obs/src/test/java/org/apache/camel/component/huaweicloud/obs/BucketMetadataFunctionalTest.java
b/components/camel-huawei/camel-huaweicloud-obs/src/test/java/org/apache/camel/component/huaweicloud/obs/BucketMetadataFunctionalTest.java
new file mode 100644
index 0000000..fdb7bb7
--- /dev/null
+++
b/components/camel-huawei/camel-huaweicloud-obs/src/test/java/org/apache/camel/component/huaweicloud/obs/BucketMetadataFunctionalTest.java
@@ -0,0 +1,71 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.huaweicloud.obs;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Ignore;
+import org.junit.Test;
+
+public class BucketMetadataFunctionalTest extends CamelTestSupport {
+
+ private static final String AUTHENTICATION_KEY =
"replace_this_with_authentication_key";
+ private static final String SECRET_KEY = "replace_this_with_secret_key";
+ private static final String REGION = "replace_this_with_region";
+ private static final String BUCKET_NAME = "replace_this_with_bucket_name";
+
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:bucket_metadata")
+ .setProperty("CamelHwCloudObsBucketName",
constant(BUCKET_NAME))
+ .to("hwcloud-obs:getBucketMetadata?" +
+ "authenticationKey=" + AUTHENTICATION_KEY +
+ "&secretKey=" + SECRET_KEY +
+ "®ion=" + REGION +
+ "&ignoreSslVerification=true")
+ .log("Get bucket metadata successful")
+ .to("log:LOG?showAll=true")
+ .to("mock:bucket_metadata_result");
+ }
+ };
+ }
+
+ /**
+ * The following test cases should be manually enabled to perform test
against the actual HuaweiCloud OBS server
+ * with real user credentials. To perform this test, manually comment out
the @Ignore annotation and enter relevant
+ * service parameters in the placeholders above (static variables of this
test class)
+ *
+ * @throws Exception
+ */
+ @Ignore("Manually enable this once you configure the parameters in the
placeholders above")
+ @Test
+ public void testListBuckets() throws Exception {
+ MockEndpoint mock = getMockEndpoint("mock:bucket_metadata_result");
+ mock.expectedMinimumMessageCount(1);
+ template.sendBody("direct:bucket_metadata", "sampleBody");
+ Exchange responseExchange = mock.getExchanges().get(0);
+
+ mock.assertIsSatisfied();
+
+ assertNotNull(responseExchange.getIn().getBody(String.class));
+ assertTrue(responseExchange.getIn().getBody(String.class).length() >
0);
+ }
+}
diff --git
a/components/camel-huawei/camel-huaweicloud-obs/src/test/java/org/apache/camel/component/huaweicloud/obs/BucketMetadataTest.java
b/components/camel-huawei/camel-huaweicloud-obs/src/test/java/org/apache/camel/component/huaweicloud/obs/BucketMetadataTest.java
new file mode 100644
index 0000000..ef4beab83
--- /dev/null
+++
b/components/camel-huawei/camel-huaweicloud-obs/src/test/java/org/apache/camel/component/huaweicloud/obs/BucketMetadataTest.java
@@ -0,0 +1,77 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.huaweicloud.obs;
+
+import com.obs.services.ObsClient;
+import com.obs.services.model.BucketMetadataInfoRequest;
+import com.obs.services.model.BucketMetadataInfoResult;
+import org.apache.camel.BindToRegistry;
+import org.apache.camel.Exchange;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.huaweicloud.obs.models.ServiceKeys;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Test;
+import org.mockito.Mockito;
+
+public class BucketMetadataTest extends CamelTestSupport {
+
+ TestConfiguration testConfiguration = new TestConfiguration();
+
+ @BindToRegistry("obsClient")
+ ObsClient mockClient = Mockito.mock(ObsClient.class);
+
+ @BindToRegistry("serviceKeys")
+ ServiceKeys serviceKeys = new ServiceKeys(
+ testConfiguration.getProperty("authenticationKey"),
+ testConfiguration.getProperty("secretKey"));
+
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:bucket_metadata")
+ .setProperty("CamelHwCloudObsBucketName",
constant(testConfiguration.getProperty("bucketName")))
+ .to("hwcloud-obs:getBucketMetadata?" +
+ "authenticationKey=" +
testConfiguration.getProperty("authenticationKey") +
+ "&secretKey=" +
testConfiguration.getProperty("secretKey") +
+ "®ion=" +
testConfiguration.getProperty("region") +
+ "&ignoreSslVerification=true" +
+ "&obsClient=#obsClient")
+ .log("Get bucket metadata successful")
+ .to("mock:bucket_metadata_result");
+ }
+ };
+ }
+
+ @Test
+ public void testGetBucketMetadata() throws Exception {
+ BucketMetadataInfoResult result
+ = new BucketMetadataInfoResult(null, null, 12, null, null,
null, "location-13", null, null);
+
Mockito.when(mockClient.getBucketMetadata(Mockito.any(BucketMetadataInfoRequest.class))).thenReturn(result);
+
+ MockEndpoint mock = getMockEndpoint("mock:bucket_metadata_result");
+ mock.expectedMinimumMessageCount(1);
+ template.sendBody("direct:bucket_metadata", "sample_body");
+ Exchange responseExchange = mock.getExchanges().get(0);
+
+ mock.assertIsSatisfied();
+
+
assertEquals("{\"location\":\"location-13\",\"bucketType\":\"OBJECT\",\"maxAge\":12,\"statusCode\":0}",
+ responseExchange.getIn().getBody(String.class));
+ }
+}
diff --git
a/components/camel-huawei/camel-huaweicloud-obs/src/test/java/org/apache/camel/component/huaweicloud/obs/constants/OBSOperationsTest.java
b/components/camel-huawei/camel-huaweicloud-obs/src/test/java/org/apache/camel/component/huaweicloud/obs/constants/OBSOperationsTest.java
index 51e8131..a74ca88 100644
---
a/components/camel-huawei/camel-huaweicloud-obs/src/test/java/org/apache/camel/component/huaweicloud/obs/constants/OBSOperationsTest.java
+++
b/components/camel-huawei/camel-huaweicloud-obs/src/test/java/org/apache/camel/component/huaweicloud/obs/constants/OBSOperationsTest.java
@@ -27,5 +27,6 @@ public class OBSOperationsTest {
assertEquals("createBucket", OBSOperations.CREATE_BUCKET);
assertEquals("deleteBucket", OBSOperations.DELETE_BUCKET);
assertEquals("checkBucketExists", OBSOperations.CHECK_BUCKET_EXISTS);
+ assertEquals("getBucketMetadata", OBSOperations.GET_BUCKET_METADATA);
}
}