You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ac...@apache.org on 2017/03/27 07:49:28 UTC
[10/20] camel git commit: Refactor com.viwilo to org.apache.camel
http://git-wip-us.apache.org/repos/asf/camel/blob/17d527d1/components/camel-digitalocean/src/main/java/com/viwilo/camel/producer/DigitalOceanKeysProducer.java
----------------------------------------------------------------------
diff --git a/components/camel-digitalocean/src/main/java/com/viwilo/camel/producer/DigitalOceanKeysProducer.java b/components/camel-digitalocean/src/main/java/com/viwilo/camel/producer/DigitalOceanKeysProducer.java
deleted file mode 100644
index bb66170..0000000
--- a/components/camel-digitalocean/src/main/java/com/viwilo/camel/producer/DigitalOceanKeysProducer.java
+++ /dev/null
@@ -1,144 +0,0 @@
-/**
- * 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 com.viwilo.camel.producer;
-
-import com.myjeeva.digitalocean.pojo.*;
-import com.viwilo.camel.DigitalOceanConfiguration;
-import com.viwilo.camel.constants.DigitalOceanHeaders;
-import com.viwilo.camel.DigitalOceanEndpoint;
-import org.apache.camel.Exchange;
-import org.apache.camel.util.ObjectHelper;
-
-/**
- * The DigitalOcean producer for SSH Keys API.
- */
-public class DigitalOceanKeysProducer extends DigitalOceanProducer {
-
- public DigitalOceanKeysProducer(DigitalOceanEndpoint endpoint, DigitalOceanConfiguration configuration) {
- super(endpoint, configuration);
- }
-
- public void process(Exchange exchange) throws Exception {
-
- switch(determineOperation(exchange)) {
-
- case list:
- getKeys(exchange);
- break;
- case create:
- createKey(exchange);
- break;
- case get:
- getKey(exchange);
- break;
- case update:
- updateKey(exchange);
- break;
- case delete:
- deleteKey(exchange);
- break;
- default:
- throw new IllegalArgumentException("Unsupported operation");
- }
- }
-
-
- private void getKey(Exchange exchange) throws Exception {
- Integer keyId = exchange.getIn().getHeader(DigitalOceanHeaders.ID, Integer.class);
- String fingerprint = exchange.getIn().getHeader(DigitalOceanHeaders.KEY_FINGERPRINT, String.class);
- Key key;
-
- if (ObjectHelper.isNotEmpty(keyId))
- key = getEndpoint().getDigitalOceanClient().getKeyInfo(keyId);
- else if (ObjectHelper.isNotEmpty(fingerprint))
- key = getEndpoint().getDigitalOceanClient().getKeyInfo(fingerprint);
- else
- throw new IllegalArgumentException(DigitalOceanHeaders.ID + " or " + DigitalOceanHeaders.KEY_FINGERPRINT + " must be specified");
-
- LOG.trace("Key [{}] ", key);
- exchange.getOut().setBody(key);
- }
-
- private void getKeys(Exchange exchange) throws Exception {
- Keys keys = getEndpoint().getDigitalOceanClient().getAvailableKeys(configuration.getPage());
- LOG.trace("All Keys : page {} [{}] ", configuration.getPage(), keys.getKeys());
- exchange.getOut().setBody(keys.getKeys());
- }
-
- private void deleteKey(Exchange exchange) throws Exception {
- Integer keyId = exchange.getIn().getHeader(DigitalOceanHeaders.ID, Integer.class);
- String fingerprint = exchange.getIn().getHeader(DigitalOceanHeaders.KEY_FINGERPRINT, String.class);
- Delete delete;
-
- if (ObjectHelper.isNotEmpty(keyId))
- delete = getEndpoint().getDigitalOceanClient().deleteKey(keyId);
- else if (ObjectHelper.isNotEmpty(fingerprint))
- delete = getEndpoint().getDigitalOceanClient().deleteKey(fingerprint);
- else
- throw new IllegalArgumentException(DigitalOceanHeaders.ID + " or " + DigitalOceanHeaders.KEY_FINGERPRINT + " must be specified");
-
- LOG.trace("Delete Key {} ", delete);
- exchange.getOut().setBody(delete);
- }
-
-
- private void createKey(Exchange exchange) throws Exception {
- Key key = new Key();
-
- String name = exchange.getIn().getHeader(DigitalOceanHeaders.NAME, String.class);
-
- if (ObjectHelper.isEmpty(name))
- throw new IllegalArgumentException(DigitalOceanHeaders.NAME + " must be specified");
- else
- key.setName(name);
-
- String publicKey = exchange.getIn().getHeader(DigitalOceanHeaders.KEY_PUBLIC_KEY, String.class);
-
- if (ObjectHelper.isEmpty(publicKey))
- throw new IllegalArgumentException(DigitalOceanHeaders.KEY_PUBLIC_KEY + " must be specified");
- else
- key.setPublicKey(publicKey);
-
- key = getEndpoint().getDigitalOceanClient().createKey(key);
- LOG.trace("Key created {} ", key);
- exchange.getOut().setBody(key);
-
- }
-
- private void updateKey(Exchange exchange) throws Exception {
- Integer keyId = exchange.getIn().getHeader(DigitalOceanHeaders.ID, Integer.class);
- String fingerprint = exchange.getIn().getHeader(DigitalOceanHeaders.KEY_FINGERPRINT, String.class);
- Key key;
-
- String name = exchange.getIn().getHeader(DigitalOceanHeaders.NAME, String.class);
-
- if (ObjectHelper.isEmpty(name))
- throw new IllegalArgumentException(DigitalOceanHeaders.NAME + " must be specified");
-
- if (ObjectHelper.isNotEmpty(keyId))
- key = getEndpoint().getDigitalOceanClient().updateKey(keyId, name);
- else if (ObjectHelper.isNotEmpty(fingerprint))
- key = getEndpoint().getDigitalOceanClient().updateKey(fingerprint, name);
- else
- throw new IllegalArgumentException(DigitalOceanHeaders.ID + " or " + DigitalOceanHeaders.KEY_FINGERPRINT + " must be specified");
-
- LOG.trace("Update Key [{}] ", key);
- exchange.getOut().setBody(key);
- }
-
-
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/17d527d1/components/camel-digitalocean/src/main/java/com/viwilo/camel/producer/DigitalOceanProducer.java
----------------------------------------------------------------------
diff --git a/components/camel-digitalocean/src/main/java/com/viwilo/camel/producer/DigitalOceanProducer.java b/components/camel-digitalocean/src/main/java/com/viwilo/camel/producer/DigitalOceanProducer.java
deleted file mode 100644
index 2ed0165..0000000
--- a/components/camel-digitalocean/src/main/java/com/viwilo/camel/producer/DigitalOceanProducer.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/**
- * 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 com.viwilo.camel.producer;
-
-import com.viwilo.camel.DigitalOceanConfiguration;
-import com.viwilo.camel.constants.DigitalOceanHeaders;
-import com.viwilo.camel.DigitalOceanEndpoint;
-import com.viwilo.camel.constants.DigitalOceanOperations;
-import org.apache.camel.Exchange;
-import org.apache.camel.impl.DefaultProducer;
-import org.apache.camel.util.ObjectHelper;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * The DigitalOcean producer.
- */
-public abstract class DigitalOceanProducer extends DefaultProducer {
- protected static final Logger LOG = LoggerFactory.getLogger(DigitalOceanProducer.class);
-
- private DigitalOceanEndpoint endpoint;
- protected DigitalOceanConfiguration configuration;
-
- public DigitalOceanProducer(DigitalOceanEndpoint endpoint, DigitalOceanConfiguration configuration) {
- super(endpoint);
- this.endpoint = endpoint;
- this.configuration = configuration;
- }
-
- protected DigitalOceanOperations determineOperation(Exchange exchange) {
- DigitalOceanOperations operation = exchange.getIn().getHeader(DigitalOceanHeaders.OPERATION, DigitalOceanOperations.class);
- return ObjectHelper.isNotEmpty(operation) ? operation : configuration.getOperation();
- }
-
- @Override
- public DigitalOceanEndpoint getEndpoint() {
- return endpoint;
- }
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/17d527d1/components/camel-digitalocean/src/main/java/com/viwilo/camel/producer/DigitalOceanRegionsProducer.java
----------------------------------------------------------------------
diff --git a/components/camel-digitalocean/src/main/java/com/viwilo/camel/producer/DigitalOceanRegionsProducer.java b/components/camel-digitalocean/src/main/java/com/viwilo/camel/producer/DigitalOceanRegionsProducer.java
deleted file mode 100644
index cda1116..0000000
--- a/components/camel-digitalocean/src/main/java/com/viwilo/camel/producer/DigitalOceanRegionsProducer.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/**
- * 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 com.viwilo.camel.producer;
-
-import com.myjeeva.digitalocean.pojo.*;
-import com.viwilo.camel.DigitalOceanConfiguration;
-import com.viwilo.camel.DigitalOceanEndpoint;
-import org.apache.camel.Exchange;
-
-/**
- * The DigitalOcean producer for Regions API.
- */
-public class DigitalOceanRegionsProducer extends DigitalOceanProducer {
-
- public DigitalOceanRegionsProducer(DigitalOceanEndpoint endpoint, DigitalOceanConfiguration configuration) {
- super(endpoint, configuration);
- }
-
- public void process(Exchange exchange) throws Exception {
- Regions regions = getEndpoint().getDigitalOceanClient().getAvailableRegions(configuration.getPage());
- LOG.trace("All Regions : page {} [{}] ", regions.getRegions(), configuration.getPage());
- exchange.getOut().setBody(regions.getRegions());
- }
-
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/17d527d1/components/camel-digitalocean/src/main/java/com/viwilo/camel/producer/DigitalOceanSizesProducer.java
----------------------------------------------------------------------
diff --git a/components/camel-digitalocean/src/main/java/com/viwilo/camel/producer/DigitalOceanSizesProducer.java b/components/camel-digitalocean/src/main/java/com/viwilo/camel/producer/DigitalOceanSizesProducer.java
deleted file mode 100644
index 0f8d622..0000000
--- a/components/camel-digitalocean/src/main/java/com/viwilo/camel/producer/DigitalOceanSizesProducer.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/**
- * 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 com.viwilo.camel.producer;
-
-import com.myjeeva.digitalocean.pojo.*;
-import com.viwilo.camel.DigitalOceanConfiguration;
-import com.viwilo.camel.DigitalOceanEndpoint;
-import org.apache.camel.Exchange;
-
-/**
- * The DigitalOcean producer for Sizes API.
- */
-public class DigitalOceanSizesProducer extends DigitalOceanProducer {
-
- public DigitalOceanSizesProducer(DigitalOceanEndpoint endpoint, DigitalOceanConfiguration configuration) {
- super(endpoint, configuration);
- }
-
- public void process(Exchange exchange) throws Exception {
- Sizes sizes = getEndpoint().getDigitalOceanClient().getAvailableSizes(configuration.getPage());
- LOG.trace("All Sizes : page {} [{}] ", sizes.getSizes(), configuration.getPage());
- exchange.getOut().setBody(sizes.getSizes());
- }
-
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/17d527d1/components/camel-digitalocean/src/main/java/com/viwilo/camel/producer/DigitalOceanSnapshotsProducer.java
----------------------------------------------------------------------
diff --git a/components/camel-digitalocean/src/main/java/com/viwilo/camel/producer/DigitalOceanSnapshotsProducer.java b/components/camel-digitalocean/src/main/java/com/viwilo/camel/producer/DigitalOceanSnapshotsProducer.java
deleted file mode 100644
index 2445529..0000000
--- a/components/camel-digitalocean/src/main/java/com/viwilo/camel/producer/DigitalOceanSnapshotsProducer.java
+++ /dev/null
@@ -1,101 +0,0 @@
-/**
- * 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 com.viwilo.camel.producer;
-
-import com.myjeeva.digitalocean.pojo.Delete;
-import com.myjeeva.digitalocean.pojo.Snapshot;
-import com.myjeeva.digitalocean.pojo.Snapshots;
-import com.viwilo.camel.DigitalOceanConfiguration;
-import com.viwilo.camel.DigitalOceanEndpoint;
-import com.viwilo.camel.constants.DigitalOceanHeaders;
-import com.viwilo.camel.constants.DigitalOceanSnapshotTypes;
-import org.apache.camel.Exchange;
-import org.apache.camel.util.ObjectHelper;
-
-/**
- * The DigitalOcean producer for Snapshots API.
- */
-public class DigitalOceanSnapshotsProducer extends DigitalOceanProducer {
-
- public DigitalOceanSnapshotsProducer(DigitalOceanEndpoint endpoint, DigitalOceanConfiguration configuration) {
- super(endpoint, configuration);
- }
-
- public void process(Exchange exchange) throws Exception {
-
- switch (determineOperation(exchange)) {
-
- case list:
- getSnapshots(exchange);
- break;
- case get:
- getSnapshot(exchange);
- break;
- case delete:
- deleteSnapshot(exchange);
- break;
-
- default:
- throw new IllegalArgumentException("Unsupported operation");
- }
-
-
- }
-
-
- private void getSnapshots(Exchange exchange) throws Exception {
- DigitalOceanSnapshotTypes type = exchange.getIn().getHeader(DigitalOceanHeaders.TYPE, DigitalOceanSnapshotTypes.class);
- Snapshots snapshots;
-
- if (ObjectHelper.isNotEmpty(type))
- if(type == DigitalOceanSnapshotTypes.droplet)
- snapshots = getEndpoint().getDigitalOceanClient().getAllDropletSnapshots(configuration.getPage(), configuration.getPerPage());
- else
- snapshots = getEndpoint().getDigitalOceanClient().getAllVolumeSnapshots(configuration.getPage(), configuration.getPerPage());
- else
- snapshots = getEndpoint().getDigitalOceanClient().getAvailableSnapshots(configuration.getPage(), configuration.getPerPage());
-
- LOG.trace("All Snapshots : page {} / {} per page [{}] ", configuration.getPage(), configuration.getPerPage(), snapshots.getSnapshots());
- exchange.getOut().setBody(snapshots.getSnapshots());
- }
-
- private void getSnapshot(Exchange exchange) throws Exception {
- String snapshotId = exchange.getIn().getHeader(DigitalOceanHeaders.ID, String.class);
-
- if (ObjectHelper.isEmpty(snapshotId))
- throw new IllegalArgumentException(DigitalOceanHeaders.ID + " must be specified");
-
- Snapshot snapshot = getEndpoint().getDigitalOceanClient().getSnaphotInfo(snapshotId);
- LOG.trace("Snapshot [{}] ", snapshot);
- exchange.getOut().setBody(snapshot);
-
- }
-
- private void deleteSnapshot(Exchange exchange) throws Exception {
- String snapshotId = exchange.getIn().getHeader(DigitalOceanHeaders.ID, String.class);
-
- if (ObjectHelper.isEmpty(snapshotId))
- throw new IllegalArgumentException(DigitalOceanHeaders.ID + " must be specified");
-
- Delete delete = getEndpoint().getDigitalOceanClient().deleteSnapshot(snapshotId);
- LOG.trace("Delete Snapshot [{}] ", delete);
- exchange.getOut().setBody(delete);
-
- }
-
-
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/17d527d1/components/camel-digitalocean/src/main/java/com/viwilo/camel/producer/DigitalOceanTagsProducer.java
----------------------------------------------------------------------
diff --git a/components/camel-digitalocean/src/main/java/com/viwilo/camel/producer/DigitalOceanTagsProducer.java b/components/camel-digitalocean/src/main/java/com/viwilo/camel/producer/DigitalOceanTagsProducer.java
deleted file mode 100644
index d797616..0000000
--- a/components/camel-digitalocean/src/main/java/com/viwilo/camel/producer/DigitalOceanTagsProducer.java
+++ /dev/null
@@ -1,114 +0,0 @@
-/**
- * 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 com.viwilo.camel.producer;
-
-import com.myjeeva.digitalocean.pojo.*;
-import com.viwilo.camel.DigitalOceanConfiguration;
-import com.viwilo.camel.constants.DigitalOceanHeaders;
-import com.viwilo.camel.DigitalOceanEndpoint;
-import org.apache.camel.Exchange;
-import org.apache.camel.util.ObjectHelper;
-
-/**
- * The DigitalOcean producer for Tags API.
- */
-public class DigitalOceanTagsProducer extends DigitalOceanProducer {
-
- public DigitalOceanTagsProducer(DigitalOceanEndpoint endpoint, DigitalOceanConfiguration configuration) {
- super(endpoint, configuration);
- }
-
- public void process(Exchange exchange) throws Exception {
- switch(determineOperation(exchange)) {
-
- case list:
- getTags(exchange);
- break;
- case create:
- createTag(exchange);
- break;
- case get:
- getTag(exchange);
- break;
- case delete:
- deleteTag(exchange);
- break;
- case update:
- updateTag(exchange);
- break;
- default:
- throw new IllegalArgumentException("Unsupported operation");
- }
-
- }
-
- private void createTag(Exchange exchange) throws Exception {
- String name = exchange.getIn().getHeader(DigitalOceanHeaders.NAME, String.class);
-
- if (ObjectHelper.isEmpty(name))
- throw new IllegalArgumentException(DigitalOceanHeaders.NAME + " must be specified");
- Tag tag = getEndpoint().getDigitalOceanClient().createTag(name);
- LOG.trace("Create Tag [{}] ", tag);
- exchange.getOut().setBody(tag);
- }
-
-
- private void getTag(Exchange exchange) throws Exception {
- String name = exchange.getIn().getHeader(DigitalOceanHeaders.NAME, String.class);
-
- if (ObjectHelper.isEmpty(name))
- throw new IllegalArgumentException(DigitalOceanHeaders.NAME + " must be specified");
- Tag tag = getEndpoint().getDigitalOceanClient().getTag(name);
- LOG.trace("Tag [{}] ", tag);
- exchange.getOut().setBody(tag);
- }
-
- private void getTags(Exchange exchange) throws Exception {
- Tags tags = getEndpoint().getDigitalOceanClient().getAvailableTags(configuration.getPage(), configuration.getPerPage());
- LOG.trace("All Tags : page {} / {} per page [{}] ", configuration.getPage(), configuration.getPerPage(), tags.getTags());
- exchange.getOut().setBody(tags.getTags());
- }
-
- private void deleteTag(Exchange exchange) throws Exception {
- String name = exchange.getIn().getHeader(DigitalOceanHeaders.NAME, String.class);
-
- if (ObjectHelper.isEmpty(name))
- throw new IllegalArgumentException(DigitalOceanHeaders.NAME + " must be specified");
- Delete delete = getEndpoint().getDigitalOceanClient().deleteTag(name);
- LOG.trace("Delete Tag [{}] ", delete);
- exchange.getOut().setBody(delete);
- }
-
- private void updateTag(Exchange exchange) throws Exception {
- String name = exchange.getIn().getHeader(DigitalOceanHeaders.NAME, String.class);
-
- if (ObjectHelper.isEmpty(name))
- throw new IllegalArgumentException(DigitalOceanHeaders.NAME + " must be specified");
-
-
- String newName = exchange.getIn().getHeader(DigitalOceanHeaders.NEW_NAME, String.class);
-
- if (ObjectHelper.isEmpty(newName))
- throw new IllegalArgumentException(DigitalOceanHeaders.NEW_NAME + " must be specified");
-
- Tag tag = getEndpoint().getDigitalOceanClient().updateTag(name, newName);
- LOG.trace("Update Tag [{}] ", tag);
- exchange.getOut().setBody(tag);
- }
-
-
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/17d527d1/components/camel-digitalocean/src/main/java/org/apache/camel/component/digitalocean/DigitalOceanComponent.java
----------------------------------------------------------------------
diff --git a/components/camel-digitalocean/src/main/java/org/apache/camel/component/digitalocean/DigitalOceanComponent.java b/components/camel-digitalocean/src/main/java/org/apache/camel/component/digitalocean/DigitalOceanComponent.java
new file mode 100644
index 0000000..74daca2
--- /dev/null
+++ b/components/camel-digitalocean/src/main/java/org/apache/camel/component/digitalocean/DigitalOceanComponent.java
@@ -0,0 +1,59 @@
+/**
+ * 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.digitalocean;
+
+import java.util.Map;
+
+import org.apache.camel.component.digitalocean.constants.DigitalOceanResources;
+import org.apache.camel.CamelContext;
+import org.apache.camel.Endpoint;
+
+import org.apache.camel.impl.UriEndpointComponent;
+import org.apache.camel.util.ObjectHelper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Represents the component that manages {@link DigitalOceanEndpoint}.
+ */
+public class DigitalOceanComponent extends UriEndpointComponent {
+
+ private static final transient Logger LOG = LoggerFactory.getLogger(DigitalOceanComponent.class);
+
+
+ public DigitalOceanComponent() {
+ super(DigitalOceanEndpoint.class);
+ }
+
+ public DigitalOceanComponent(CamelContext context) {
+ super(context, DigitalOceanEndpoint.class);
+ }
+
+ protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
+
+ DigitalOceanConfiguration configuration = new DigitalOceanConfiguration();
+ setProperties(configuration, parameters);
+ configuration.setResource(DigitalOceanResources.valueOf(remaining));
+
+ if (ObjectHelper.isEmpty(configuration.getOAuthToken()) && ObjectHelper.isEmpty(configuration.getDigitalOceanClient()))
+ throw new DigitalOceanException("oAuthToken or digitalOceanClient must be specified");
+
+ Endpoint endpoint = new DigitalOceanEndpoint(uri, this, configuration);
+ return endpoint;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/17d527d1/components/camel-digitalocean/src/main/java/org/apache/camel/component/digitalocean/DigitalOceanConfiguration.java
----------------------------------------------------------------------
diff --git a/components/camel-digitalocean/src/main/java/org/apache/camel/component/digitalocean/DigitalOceanConfiguration.java b/components/camel-digitalocean/src/main/java/org/apache/camel/component/digitalocean/DigitalOceanConfiguration.java
new file mode 100644
index 0000000..895fa89
--- /dev/null
+++ b/components/camel-digitalocean/src/main/java/org/apache/camel/component/digitalocean/DigitalOceanConfiguration.java
@@ -0,0 +1,173 @@
+/**
+ * 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.digitalocean;
+
+import com.myjeeva.digitalocean.impl.DigitalOceanClient;
+import org.apache.camel.component.digitalocean.constants.DigitalOceanResources;
+import org.apache.camel.component.digitalocean.constants.DigitalOceanOperations;
+import org.apache.camel.spi.Metadata;
+import org.apache.camel.spi.UriParam;
+import org.apache.camel.spi.UriParams;
+import org.apache.camel.spi.UriPath;
+
+@UriParams
+public class DigitalOceanConfiguration {
+
+
+ @UriParam(enums = "account,actions,blockStorages,droplets,mages,snapshots,keys,regions,sizes,floatingIPs,tags")
+ @Metadata(required = "true")
+ private DigitalOceanResources resource;
+
+ @UriPath(enums = "create,update,delete,list,ownList,get,listBackups,listActions,listNeighbors,listSnapshots,listKernels,listAllNeighbors," +
+ "enableBackups,disableBackups,reboot,powerCycle,shutdown,powerOn,powerOff,restore,resetPassword," +
+ "resize,rebuild,rename,changeKernel,enableIpv6,enablePrivateNetworking,takeSnapshot,transfer,convert," +
+ "attach,detach,assign,unassign,tag,untag")
+ private DigitalOceanOperations operation;
+
+ @UriParam
+ private DigitalOceanClient digitalOceanClient;
+
+ @UriParam(label = "security", secret = true)
+ private String oAuthToken;
+
+ @UriParam(defaultValue = "1")
+ private Integer page = 1;
+
+ @UriParam(defaultValue = "25")
+ private Integer perPage = 25;
+
+
+ @UriParam(label = "proxy")
+ private String httpProxyHost;
+ @UriParam(label = "proxy")
+ private String httpProxyUser;
+ @UriParam(label = "proxy")
+ private String httpProxyPassword;
+ @UriParam(label = "proxy")
+ private Integer httpProxyPort;
+
+ public DigitalOceanResources getResource() {
+ return resource;
+ }
+
+ /**
+ * The DigitalOcean resource type on which perform the operation.
+ */
+ public void setResource(DigitalOceanResources resource) {
+ this.resource = resource;
+ }
+
+ /**
+ * The operation to perform to the given resource.
+ */
+ public DigitalOceanOperations getOperation() {
+ return operation;
+ }
+
+ public void setOperation(DigitalOceanOperations operation) {
+ this.operation = operation;
+ }
+
+ public String getOAuthToken() {
+ return oAuthToken;
+ }
+
+ /**
+ * DigitalOcean OAuth Token
+ */
+ public void setOAuthToken(String oAuthToken) {
+ this.oAuthToken = oAuthToken;
+ }
+
+ /**
+ * Use for pagination. Set the number of item per request. The maximum number of results per page is 200.
+ */
+ public Integer getPerPage() {
+ return perPage;
+ }
+
+ public void setPerPage(Integer perPage) {
+ this.perPage = perPage;
+ }
+
+ /**
+ * Use for paginsation. Force the page number.
+ */
+ public Integer getPage() {
+ return page;
+ }
+
+ public void setPage(Integer page) {
+ this.page = page;
+ }
+
+ /**
+ * Set a proxy host if needed
+ */
+ public String getHttpProxyHost() {
+ return httpProxyHost;
+ }
+
+ public void setHttpProxyHost(String httpProxyHost) {
+ this.httpProxyHost = httpProxyHost;
+ }
+
+ /**
+ * Set a proxy user if needed
+ */
+ public String getHttpProxyUser() {
+ return httpProxyUser;
+ }
+
+ public void setHttpProxyUser(String httpProxyUser) {
+ this.httpProxyUser = httpProxyUser;
+ }
+
+ /**
+ * Set a proxy password if needed
+ */
+ public String getHttpProxyPassword() {
+ return httpProxyPassword;
+ }
+
+ public void setHttpProxyPassword(String httpProxyPassword) {
+ this.httpProxyPassword = httpProxyPassword;
+ }
+
+ /**
+ * Set a proxy port if needed
+ */
+ public Integer getHttpProxyPort() {
+ return httpProxyPort;
+ }
+
+ public void setHttpProxyPort(Integer httpProxyPort) {
+ this.httpProxyPort = httpProxyPort;
+ }
+
+
+ /**
+ * To use a existing configured DigitalOceanClient as client
+ */
+ public DigitalOceanClient getDigitalOceanClient() {
+ return digitalOceanClient;
+ }
+
+ public void setDigitalOceanClient(DigitalOceanClient digitalOceanClient) {
+ this.digitalOceanClient = digitalOceanClient;
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/17d527d1/components/camel-digitalocean/src/main/java/org/apache/camel/component/digitalocean/DigitalOceanEndpoint.java
----------------------------------------------------------------------
diff --git a/components/camel-digitalocean/src/main/java/org/apache/camel/component/digitalocean/DigitalOceanEndpoint.java b/components/camel-digitalocean/src/main/java/org/apache/camel/component/digitalocean/DigitalOceanEndpoint.java
new file mode 100644
index 0000000..576e22c
--- /dev/null
+++ b/components/camel-digitalocean/src/main/java/org/apache/camel/component/digitalocean/DigitalOceanEndpoint.java
@@ -0,0 +1,130 @@
+/**
+ * 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.digitalocean;
+
+import com.myjeeva.digitalocean.impl.DigitalOceanClient;
+import org.apache.camel.Consumer;
+import org.apache.camel.Processor;
+import org.apache.camel.Producer;
+import org.apache.camel.component.digitalocean.producer.*;
+import org.apache.camel.impl.DefaultEndpoint;
+import org.apache.camel.spi.UriEndpoint;
+import org.apache.camel.spi.UriParam;
+import org.apache.http.HttpHost;
+import org.apache.http.auth.AuthScope;
+import org.apache.http.auth.UsernamePasswordCredentials;
+import org.apache.http.impl.client.BasicCredentialsProvider;
+import org.apache.http.impl.client.HttpClientBuilder;
+import org.apache.http.impl.client.HttpClients;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Represents the DigitalOcean endpoint.
+ */
+@UriEndpoint(scheme = "digitalocean", title = "DigitalOcean", syntax="digitalocean:label", producerOnly = true, label = "cloud,management")
+public class DigitalOceanEndpoint extends DefaultEndpoint {
+
+ private static final transient Logger LOG = LoggerFactory.getLogger(DigitalOceanEndpoint.class);
+
+ @UriParam
+ private DigitalOceanConfiguration configuration;
+
+ private DigitalOceanClient digitalOceanClient;
+
+ public DigitalOceanEndpoint(String uri, DigitalOceanComponent component, DigitalOceanConfiguration configuration) {
+ super(uri, component);
+ this.configuration = configuration;
+ }
+
+ public Producer createProducer() throws Exception {
+ LOG.trace("Resolve producer digitalocean endpoint {" + configuration.getResource() + "}");
+
+ switch (configuration.getResource()) {
+ case account:
+ return new DigitalOceanAccountProducer(this, configuration);
+ case actions:
+ return new DigitalOceanActionsProducer(this, configuration);
+ case blockStorages:
+ return new DigitalOceanBlockStoragesProducer(this, configuration);
+ case droplets:
+ return new DigitalOceanDropletsProducer(this, configuration);
+ case images:
+ return new DigitalOceanImagesProducer(this, configuration);
+ case snapshots:
+ return new DigitalOceanSnapshotsProducer(this, configuration);
+ case keys:
+ return new DigitalOceanKeysProducer(this, configuration);
+ case regions:
+ return new DigitalOceanRegionsProducer(this, configuration);
+ case sizes:
+ return new DigitalOceanSizesProducer(this, configuration);
+ case floatingIPs:
+ return new DigitalOceanFloatingIPsProducer(this, configuration);
+ case tags:
+ return new DigitalOceanTagsProducer(this, configuration);
+ default:
+ throw new UnsupportedOperationException("Operation specified is not valid for producer");
+ }
+
+ }
+
+ public Consumer createConsumer(Processor processor) throws Exception {
+ throw new UnsupportedOperationException("You cannot receive messages from this endpoint");
+ }
+
+ public boolean isSingleton() {
+ return true;
+ }
+
+
+ @Override
+ public void doStart() throws Exception {
+ super.doStart();
+
+ if(configuration.getDigitalOceanClient() != null)
+ digitalOceanClient = configuration.getDigitalOceanClient();
+ else
+ if(configuration.getHttpProxyHost() != null && configuration.getHttpProxyPort() != null) {
+
+ HttpClientBuilder builder = HttpClients.custom()
+ .useSystemProperties()
+ .setProxy(new HttpHost(configuration.getHttpProxyHost(), configuration.getHttpProxyPort()));
+
+ if(configuration.getHttpProxyUser() != null && configuration.getHttpProxyPassword() != null) {
+ BasicCredentialsProvider credsProvider = new BasicCredentialsProvider();
+ credsProvider.setCredentials(
+ new AuthScope(configuration.getHttpProxyHost(), configuration.getHttpProxyPort()),
+ new UsernamePasswordCredentials(configuration.getHttpProxyUser() , configuration.getHttpProxyPassword()));
+ builder.setDefaultCredentialsProvider(credsProvider);
+
+ }
+
+ digitalOceanClient = new DigitalOceanClient("v2", configuration.getOAuthToken(), builder.build());
+
+ } else
+ digitalOceanClient = new DigitalOceanClient(configuration.getOAuthToken());
+
+
+ }
+
+ public DigitalOceanConfiguration getConfiguration() { return configuration; }
+ public DigitalOceanClient getDigitalOceanClient() {
+ return digitalOceanClient;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/17d527d1/components/camel-digitalocean/src/main/java/org/apache/camel/component/digitalocean/DigitalOceanException.java
----------------------------------------------------------------------
diff --git a/components/camel-digitalocean/src/main/java/org/apache/camel/component/digitalocean/DigitalOceanException.java b/components/camel-digitalocean/src/main/java/org/apache/camel/component/digitalocean/DigitalOceanException.java
new file mode 100644
index 0000000..a149fd4
--- /dev/null
+++ b/components/camel-digitalocean/src/main/java/org/apache/camel/component/digitalocean/DigitalOceanException.java
@@ -0,0 +1,30 @@
+/**
+ * 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.digitalocean;
+
+public class DigitalOceanException extends Exception {
+
+ private static final long serialVersionUID = 1L;
+
+ public DigitalOceanException(Throwable e) {
+ super(e);
+ }
+
+ public DigitalOceanException(String message) {
+ super(message);
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/17d527d1/components/camel-digitalocean/src/main/java/org/apache/camel/component/digitalocean/constants/DigitalOceanHeaders.java
----------------------------------------------------------------------
diff --git a/components/camel-digitalocean/src/main/java/org/apache/camel/component/digitalocean/constants/DigitalOceanHeaders.java b/components/camel-digitalocean/src/main/java/org/apache/camel/component/digitalocean/constants/DigitalOceanHeaders.java
new file mode 100644
index 0000000..d4462c2
--- /dev/null
+++ b/components/camel-digitalocean/src/main/java/org/apache/camel/component/digitalocean/constants/DigitalOceanHeaders.java
@@ -0,0 +1,54 @@
+/**
+ * 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.digitalocean.constants;
+
+public interface DigitalOceanHeaders {
+
+ String OPERATION = "CamelDigitalOceanOperation";
+ String ID = "CamelDigitalOceanId";
+ String TYPE = "CamelDigitalOceanType";
+ String NAME = "CamelDigitalOceanName";
+ String NEW_NAME = "CamelDigitalOceanNewName";
+ String NAMES = "CamelDigitalOceanNames";
+ String REGION = "CamelDigitalOceanRegion";
+ String DESCRIPTION = "CamelDigitalOceanDescription";
+
+ String DROPLET_SIZE = "CamelDigitalOceanDropletSize";
+ String DROPLET_IMAGE = "CamelDigitalOceanDropletImage";
+ String DROPLET_KEYS = "CamelDigitalOceanDropletSSHKeys";
+ String DROPLET_ENABLE_BACKUPS = "CamelDigitalOceanDropletEnableBackups";
+ String DROPLET_ENABLE_IPV6 = "CamelDigitalOceanDropletEnableIpv6";
+ String DROPLET_ENABLE_PRIVATE_NETWORKING = "CamelDigitalOceanDropletEnablePrivateNetworking";
+ String DROPLET_USER_DATA = "CamelDigitalOceanDropletUserData";
+ String DROPLET_VOLUMES = "CamelDigitalOceanDropletVolumes";
+ String DROPLET_TAGS = "CamelDigitalOceanDropletTags";
+
+ String DROPLET_ID = "CamelDigitalOceanDropletId";
+ String IMAGE_ID = "CamelDigitalOceanImageId";
+ String KERNEL_ID = "CamelDigitalOceanKernelId";
+ String VOLUME_NAME = "CamelDigitalOceanVolumeName";
+ String VOLUME_SIZE_GIGABYTES = "CamelDigitalOceanVolumeSizeGigabytes";
+
+ String FLOATING_IP_ADDRESS = "CamelDigitalOceanFloatingIPAddress";
+
+ String KEY_FINGERPRINT = "CamelDigitalOceanKeyFingerprint";
+ String KEY_PUBLIC_KEY = "CamelDigitalOceanKeyPublicKey";
+
+
+
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/17d527d1/components/camel-digitalocean/src/main/java/org/apache/camel/component/digitalocean/constants/DigitalOceanImageTypes.java
----------------------------------------------------------------------
diff --git a/components/camel-digitalocean/src/main/java/org/apache/camel/component/digitalocean/constants/DigitalOceanImageTypes.java b/components/camel-digitalocean/src/main/java/org/apache/camel/component/digitalocean/constants/DigitalOceanImageTypes.java
new file mode 100644
index 0000000..f5c4a12
--- /dev/null
+++ b/components/camel-digitalocean/src/main/java/org/apache/camel/component/digitalocean/constants/DigitalOceanImageTypes.java
@@ -0,0 +1,24 @@
+/**
+ * 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.digitalocean.constants;
+
+public enum DigitalOceanImageTypes {
+
+ distribution,
+ application
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/17d527d1/components/camel-digitalocean/src/main/java/org/apache/camel/component/digitalocean/constants/DigitalOceanOperations.java
----------------------------------------------------------------------
diff --git a/components/camel-digitalocean/src/main/java/org/apache/camel/component/digitalocean/constants/DigitalOceanOperations.java b/components/camel-digitalocean/src/main/java/org/apache/camel/component/digitalocean/constants/DigitalOceanOperations.java
new file mode 100644
index 0000000..8677c38
--- /dev/null
+++ b/components/camel-digitalocean/src/main/java/org/apache/camel/component/digitalocean/constants/DigitalOceanOperations.java
@@ -0,0 +1,57 @@
+/**
+ * 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.digitalocean.constants;
+
+public enum DigitalOceanOperations {
+
+ create,
+ update,
+ delete,
+ list,
+ ownList,
+ get,
+ listBackups,
+ listActions,
+ listNeighbors,
+ listSnapshots,
+ listKernels,
+ listAllNeighbors,
+ enableBackups,
+ disableBackups,
+ reboot,
+ powerCycle,
+ shutdown,
+ powerOn,
+ powerOff,
+ restore,
+ resetPassword,
+ resize,
+ rebuild,
+ rename,
+ changeKernel,
+ enableIpv6,
+ enablePrivateNetworking,
+ takeSnapshot,
+ transfer,
+ convert,
+ attach,
+ detach,
+ assign,
+ unassign,
+ tag,
+ untag
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/17d527d1/components/camel-digitalocean/src/main/java/org/apache/camel/component/digitalocean/constants/DigitalOceanResources.java
----------------------------------------------------------------------
diff --git a/components/camel-digitalocean/src/main/java/org/apache/camel/component/digitalocean/constants/DigitalOceanResources.java b/components/camel-digitalocean/src/main/java/org/apache/camel/component/digitalocean/constants/DigitalOceanResources.java
new file mode 100644
index 0000000..8188cb8
--- /dev/null
+++ b/components/camel-digitalocean/src/main/java/org/apache/camel/component/digitalocean/constants/DigitalOceanResources.java
@@ -0,0 +1,36 @@
+/**
+ * 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.digitalocean.constants;
+
+
+public enum DigitalOceanResources {
+
+ account,
+ actions,
+ blockStorages,
+ droplets,
+ images,
+ snapshots,
+ keys,
+ regions,
+ sizes,
+ floatingIPs,
+ tags
+
+
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/17d527d1/components/camel-digitalocean/src/main/java/org/apache/camel/component/digitalocean/constants/DigitalOceanSnapshotTypes.java
----------------------------------------------------------------------
diff --git a/components/camel-digitalocean/src/main/java/org/apache/camel/component/digitalocean/constants/DigitalOceanSnapshotTypes.java b/components/camel-digitalocean/src/main/java/org/apache/camel/component/digitalocean/constants/DigitalOceanSnapshotTypes.java
new file mode 100644
index 0000000..f08a461
--- /dev/null
+++ b/components/camel-digitalocean/src/main/java/org/apache/camel/component/digitalocean/constants/DigitalOceanSnapshotTypes.java
@@ -0,0 +1,24 @@
+/**
+ * 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.digitalocean.constants;
+
+public enum DigitalOceanSnapshotTypes {
+
+ droplet,
+ volume
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/17d527d1/components/camel-digitalocean/src/main/java/org/apache/camel/component/digitalocean/producer/DigitalOceanAccountProducer.java
----------------------------------------------------------------------
diff --git a/components/camel-digitalocean/src/main/java/org/apache/camel/component/digitalocean/producer/DigitalOceanAccountProducer.java b/components/camel-digitalocean/src/main/java/org/apache/camel/component/digitalocean/producer/DigitalOceanAccountProducer.java
new file mode 100644
index 0000000..dddc1a5
--- /dev/null
+++ b/components/camel-digitalocean/src/main/java/org/apache/camel/component/digitalocean/producer/DigitalOceanAccountProducer.java
@@ -0,0 +1,39 @@
+/**
+ * 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.digitalocean.producer;
+
+import com.myjeeva.digitalocean.pojo.*;
+import org.apache.camel.component.digitalocean.DigitalOceanConfiguration;
+import org.apache.camel.component.digitalocean.DigitalOceanEndpoint;
+import org.apache.camel.Exchange;
+
+/**
+ * The DigitalOcean producer for Account API.
+ */
+public class DigitalOceanAccountProducer extends DigitalOceanProducer {
+
+ public DigitalOceanAccountProducer(DigitalOceanEndpoint endpoint, DigitalOceanConfiguration configuration) {
+ super(endpoint, configuration);
+ }
+
+ public void process(Exchange exchange) throws Exception {
+ Account accountInfo = getEndpoint().getDigitalOceanClient().getAccountInfo();
+ LOG.trace("Account [{}] ", accountInfo);
+ exchange.getOut().setBody(accountInfo);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/17d527d1/components/camel-digitalocean/src/main/java/org/apache/camel/component/digitalocean/producer/DigitalOceanActionsProducer.java
----------------------------------------------------------------------
diff --git a/components/camel-digitalocean/src/main/java/org/apache/camel/component/digitalocean/producer/DigitalOceanActionsProducer.java b/components/camel-digitalocean/src/main/java/org/apache/camel/component/digitalocean/producer/DigitalOceanActionsProducer.java
new file mode 100644
index 0000000..67fdd67
--- /dev/null
+++ b/components/camel-digitalocean/src/main/java/org/apache/camel/component/digitalocean/producer/DigitalOceanActionsProducer.java
@@ -0,0 +1,66 @@
+/**
+ * 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.digitalocean.producer;
+
+import com.myjeeva.digitalocean.pojo.*;
+import org.apache.camel.component.digitalocean.DigitalOceanConfiguration;
+import org.apache.camel.component.digitalocean.DigitalOceanEndpoint;
+import org.apache.camel.component.digitalocean.constants.DigitalOceanHeaders;
+import org.apache.camel.Exchange;
+import org.apache.camel.util.ObjectHelper;
+
+/**
+ * The DigitalOcean producer for Actions API.
+ */
+public class DigitalOceanActionsProducer extends DigitalOceanProducer {
+
+ public DigitalOceanActionsProducer(DigitalOceanEndpoint endpoint, DigitalOceanConfiguration configuration) {
+ super(endpoint, configuration);
+ }
+
+ public void process(Exchange exchange) throws Exception {
+ switch(determineOperation(exchange)) {
+
+ case list:
+ getActions(exchange);
+ break;
+ case get:
+ getAction(exchange);
+ break;
+ default:
+ throw new IllegalArgumentException("Unsupported operation");
+ }
+
+ }
+
+
+ private void getAction(Exchange exchange) throws Exception {
+ Integer actionId = exchange.getIn().getHeader(DigitalOceanHeaders.ID, Integer.class);
+
+ if (ObjectHelper.isEmpty(actionId))
+ throw new IllegalArgumentException(DigitalOceanHeaders.ID + " must be specified");
+ Action action = getEndpoint().getDigitalOceanClient().getActionInfo(actionId);
+ LOG.trace("Action [{}] ", action);
+ exchange.getOut().setBody(action);
+ }
+
+ private void getActions(Exchange exchange) throws Exception {
+ Actions actions = getEndpoint().getDigitalOceanClient().getAvailableActions(configuration.getPage(), configuration.getPerPage());
+ LOG.trace("All Actions : page {} / {} per page [{}] ", configuration.getPage(), configuration.getPerPage(), actions.getActions());
+ exchange.getOut().setBody(actions.getActions());
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/17d527d1/components/camel-digitalocean/src/main/java/org/apache/camel/component/digitalocean/producer/DigitalOceanBlockStoragesProducer.java
----------------------------------------------------------------------
diff --git a/components/camel-digitalocean/src/main/java/org/apache/camel/component/digitalocean/producer/DigitalOceanBlockStoragesProducer.java b/components/camel-digitalocean/src/main/java/org/apache/camel/component/digitalocean/producer/DigitalOceanBlockStoragesProducer.java
new file mode 100644
index 0000000..0e00507
--- /dev/null
+++ b/components/camel-digitalocean/src/main/java/org/apache/camel/component/digitalocean/producer/DigitalOceanBlockStoragesProducer.java
@@ -0,0 +1,252 @@
+/**
+ * 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.digitalocean.producer;
+
+import com.myjeeva.digitalocean.pojo.*;
+import org.apache.camel.component.digitalocean.DigitalOceanConfiguration;
+import org.apache.camel.component.digitalocean.constants.DigitalOceanHeaders;
+import org.apache.camel.component.digitalocean.DigitalOceanEndpoint;
+import org.apache.camel.Exchange;
+import org.apache.camel.Message;
+import org.apache.camel.util.ObjectHelper;
+
+import java.util.List;
+
+/**
+ * The DigitalOcean producer for BlockStorages API.
+ */
+public class DigitalOceanBlockStoragesProducer extends DigitalOceanProducer {
+
+ public DigitalOceanBlockStoragesProducer(DigitalOceanEndpoint endpoint, DigitalOceanConfiguration configuration) {
+ super(endpoint, configuration);
+ }
+
+ public void process(Exchange exchange) throws Exception {
+
+ switch (determineOperation(exchange)) {
+
+ case list:
+ getVolumes(exchange);
+ break;
+ case get:
+ getVolume(exchange);
+ break;
+ case listSnapshots:
+ getVolumeSnapshots(exchange);
+ break;
+ case create:
+ createVolume(exchange);
+ break;
+ case delete:
+ deleteVolume(exchange);
+ break;
+ case attach:
+ attachVolumeToDroplet(exchange);
+ break;
+ case detach:
+ detachVolumeToDroplet(exchange);
+ break;
+ case resize:
+ resizeVolume(exchange);
+ break;
+ case listActions:
+ getVolumeActions(exchange);
+ break;
+ default:
+ throw new IllegalArgumentException("Unsupported operation");
+ }
+ }
+
+ private void getVolumes(Exchange exchange) throws Exception {
+ String region = exchange.getIn().getHeader(DigitalOceanHeaders.REGION, String.class);
+ if (ObjectHelper.isEmpty(region))
+ throw new IllegalArgumentException(DigitalOceanHeaders.REGION + " must be specified");
+
+ Volumes volumes = getEndpoint().getDigitalOceanClient().getAvailableVolumes(region);
+ LOG.trace("All Volumes for region {} [{}] ", region, volumes.getVolumes());
+ exchange.getOut().setBody(volumes.getVolumes());
+
+ }
+
+ private void createVolume(Exchange exchange) throws Exception {
+ Message in = exchange.getIn();
+
+ Volume volume = new Volume();
+
+ if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(DigitalOceanHeaders.VOLUME_SIZE_GIGABYTES)))
+ volume.setSize(in.getHeader(DigitalOceanHeaders.VOLUME_SIZE_GIGABYTES, Double.class));
+ else
+ throw new IllegalArgumentException(DigitalOceanHeaders.VOLUME_SIZE_GIGABYTES + " must be specified");
+
+ if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(DigitalOceanHeaders.NAME)))
+ volume.setName(in.getHeader(DigitalOceanHeaders.NAME, String.class));
+ else
+ throw new IllegalArgumentException(DigitalOceanHeaders.NAME + " must be specified");
+
+ if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(DigitalOceanHeaders.REGION)))
+ volume.setRegion(new Region(in.getHeader(DigitalOceanHeaders.REGION, String.class)));
+ else
+ throw new IllegalArgumentException(DigitalOceanHeaders.REGION + " must be specified");
+
+ if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(DigitalOceanHeaders.DESCRIPTION)))
+ volume.setDescription(in.getHeader(DigitalOceanHeaders.DESCRIPTION, String.class));
+ else
+ throw new IllegalArgumentException(DigitalOceanHeaders.DESCRIPTION + " must be specified");
+
+ volume = getEndpoint().getDigitalOceanClient().createVolume(volume);
+ LOG.trace("Volume created {} ", volume);
+ exchange.getOut().setBody(volume);
+ }
+
+ private void getVolume(Exchange exchange) throws Exception {
+ String volumeId = exchange.getIn().getHeader(DigitalOceanHeaders.ID, String.class);
+ Volume volume = null;
+ if (ObjectHelper.isEmpty(volumeId)) {
+ String name = exchange.getIn().getHeader(DigitalOceanHeaders.NAME, String.class);
+ String region = exchange.getIn().getHeader(DigitalOceanHeaders.REGION, String.class);
+
+ if (ObjectHelper.isEmpty(name) && ObjectHelper.isEmpty(region))
+ throw new IllegalArgumentException(DigitalOceanHeaders.ID + " or " + DigitalOceanHeaders.NAME + " and " + DigitalOceanHeaders.REGION + " must be specified");
+
+ List<Volume> volumes = getEndpoint().getDigitalOceanClient().getVolumeInfo(name, region).getVolumes();
+ if (volumes.size() > 0)
+ volume = volumes.get(1);
+ } else
+ volume = getEndpoint().getDigitalOceanClient().getVolumeInfo(volumeId);
+
+ LOG.trace("Volume [{}] ", volume);
+ exchange.getOut().setBody(volume);
+
+ }
+
+ private void getVolumeSnapshots(Exchange exchange) throws Exception {
+ String volumeId = exchange.getIn().getHeader(DigitalOceanHeaders.ID, String.class);
+ if (ObjectHelper.isEmpty(volumeId))
+ throw new IllegalArgumentException(DigitalOceanHeaders.ID + " must be specified");
+
+ Snapshots snapshots = getEndpoint().getDigitalOceanClient().getVolumeSnapshots(volumeId, configuration.getPage(), configuration.getPerPage());
+ LOG.trace("All Snapshots for volume {} [{}] ", volumeId, snapshots.getSnapshots());
+ exchange.getOut().setBody(snapshots.getSnapshots());
+ }
+
+ private void deleteVolume(Exchange exchange) throws Exception {
+ String volumeId = exchange.getIn().getHeader(DigitalOceanHeaders.ID, String.class);
+ Delete delete;
+ if (ObjectHelper.isEmpty(volumeId)) {
+ String name = exchange.getIn().getHeader(DigitalOceanHeaders.NAME, String.class);
+ String region = exchange.getIn().getHeader(DigitalOceanHeaders.REGION, String.class);
+
+ if (ObjectHelper.isEmpty(name) && ObjectHelper.isEmpty(region))
+ throw new IllegalArgumentException(DigitalOceanHeaders.ID + " or " + DigitalOceanHeaders.NAME + " and " + DigitalOceanHeaders.REGION + " must be specified");
+
+ delete = getEndpoint().getDigitalOceanClient().deleteVolume(name, region);
+
+ } else
+ delete = getEndpoint().getDigitalOceanClient().deleteVolume(volumeId);
+
+ LOG.trace("Delete Volume [{}] ", delete);
+ exchange.getOut().setBody(delete);
+
+ }
+
+ private void attachVolumeToDroplet(Exchange exchange) throws Exception {
+ String volumeId = exchange.getIn().getHeader(DigitalOceanHeaders.ID, String.class);
+ String volumeName = exchange.getIn().getHeader(DigitalOceanHeaders.VOLUME_NAME, String.class);
+ Integer dropletId = exchange.getIn().getHeader(DigitalOceanHeaders.DROPLET_ID, Integer.class);
+ String region = exchange.getIn().getHeader(DigitalOceanHeaders.REGION, String.class);
+
+ if (ObjectHelper.isEmpty(dropletId))
+ throw new IllegalArgumentException(DigitalOceanHeaders.DROPLET_ID + " must be specified");
+
+ if (ObjectHelper.isEmpty(region))
+ throw new IllegalArgumentException(DigitalOceanHeaders.REGION + " must be specified");
+
+ Action action;
+
+ if (ObjectHelper.isNotEmpty(volumeName)) {
+ action = getEndpoint().getDigitalOceanClient().attachVolumeByName(dropletId, volumeName, region);
+ LOG.trace("Attach Volume {} to Droplet {} [{}] ", volumeName, dropletId, action);
+ } else if (ObjectHelper.isNotEmpty(volumeId)) {
+ action = getEndpoint().getDigitalOceanClient().attachVolume(dropletId, volumeId, region);
+ LOG.trace("Attach Volume {} to Droplet {} [{}] ", volumeId, dropletId, action);
+ } else
+ throw new IllegalArgumentException(DigitalOceanHeaders.ID + " or " + DigitalOceanHeaders.VOLUME_NAME + " must be specified");
+
+ exchange.getOut().setBody(action);
+ }
+
+
+
+ private void detachVolumeToDroplet(Exchange exchange) throws Exception {
+ String volumeId = exchange.getIn().getHeader(DigitalOceanHeaders.ID, String.class);
+ String volumeName = exchange.getIn().getHeader(DigitalOceanHeaders.VOLUME_NAME, String.class);
+ Integer dropletId = exchange.getIn().getHeader(DigitalOceanHeaders.DROPLET_ID, Integer.class);
+ String region = exchange.getIn().getHeader(DigitalOceanHeaders.REGION, String.class);
+
+ if (ObjectHelper.isEmpty(dropletId))
+ throw new IllegalArgumentException(DigitalOceanHeaders.DROPLET_ID + " must be specified");
+
+ if (ObjectHelper.isEmpty(region))
+ throw new IllegalArgumentException(DigitalOceanHeaders.REGION + " must be specified");
+
+ Action action;
+
+ if (ObjectHelper.isNotEmpty(volumeName)) {
+ action = getEndpoint().getDigitalOceanClient().detachVolumeByName(dropletId, volumeName, region);
+ LOG.trace("Detach Volume {} to Droplet {} [{}] ", volumeName, dropletId, action);
+ } else if (ObjectHelper.isNotEmpty(volumeId)) {
+ action = getEndpoint().getDigitalOceanClient().detachVolume(dropletId, volumeId, region);
+ LOG.trace("Detach Volume {} to Droplet {} [{}] ", volumeId, dropletId, action);
+ } else
+ throw new IllegalArgumentException(DigitalOceanHeaders.ID + " or " + DigitalOceanHeaders.VOLUME_NAME + " must be specified");
+
+ exchange.getOut().setBody(action);
+
+ }
+
+ private void resizeVolume(Exchange exchange) throws Exception {
+ String volumeId = exchange.getIn().getHeader(DigitalOceanHeaders.ID, String.class);
+
+ if (ObjectHelper.isEmpty(volumeId))
+ throw new IllegalArgumentException(DigitalOceanHeaders.ID + " must be specified");
+
+ String region = exchange.getIn().getHeader(DigitalOceanHeaders.REGION, String.class);
+
+ if (ObjectHelper.isEmpty(region))
+ throw new IllegalArgumentException(DigitalOceanHeaders.REGION + " must be specified");
+
+ Double size = exchange.getIn().getHeader(DigitalOceanHeaders.VOLUME_SIZE_GIGABYTES, Double.class);
+
+ if (ObjectHelper.isEmpty(size))
+ throw new IllegalArgumentException(DigitalOceanHeaders.VOLUME_SIZE_GIGABYTES + " must be specified");
+
+ Action action = getEndpoint().getDigitalOceanClient().resizeVolume(volumeId, region, size);
+ LOG.trace("Resize Volume {} [{}] ", volumeId, action);
+ }
+
+ private void getVolumeActions(Exchange exchange) throws Exception {
+ String volumeId = exchange.getIn().getHeader(DigitalOceanHeaders.ID, String.class);
+
+ if (ObjectHelper.isEmpty(volumeId))
+ throw new IllegalArgumentException(DigitalOceanHeaders.ID + " must be specified");
+
+ Actions actions = getEndpoint().getDigitalOceanClient().getAvailableVolumeActions(volumeId);
+ LOG.trace("Actions for Volume {} [{}] ", volumeId, actions.getActions());
+ exchange.getOut().setBody(actions.getActions());
+ }
+
+}