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 2016/12/17 11:53:45 UTC

[06/17] camel git commit: CAMEL-9748: camel-component cinder

CAMEL-9748: camel-component cinder


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/fd9e822a
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/fd9e822a
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/fd9e822a

Branch: refs/heads/master
Commit: fd9e822ac268bb15035f10278e4bf3f9e0e6c109
Parents: 5523209
Author: Jan Bouska <jb...@redhat.com>
Authored: Fri Nov 18 19:13:10 2016 +0100
Committer: Andrea Cosentino <an...@gmail.com>
Committed: Sat Dec 17 12:25:13 2016 +0100

----------------------------------------------------------------------
 .../openstack/cinder/CinderComponent.java       |  32 ++++
 .../openstack/cinder/CinderConstants.java       |  23 +++
 .../openstack/cinder/CinderEndpoint.java        | 158 ++++++++++++++++++
 .../cinder/producer/SnapshotProducer.java       | 129 +++++++++++++++
 .../cinder/producer/VolumeProducer.java         | 148 +++++++++++++++++
 .../org/apache/camel/component/openstack-cinder |   1 +
 .../cinder/CinderProducerTestSupport.java       |  50 ++++++
 .../openstack/cinder/VolumeProducerTest.java    | 159 +++++++++++++++++++
 .../cinder/VolumeSnapshotProducerTest.java      | 136 ++++++++++++++++
 9 files changed, 836 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/fd9e822a/components/camel-openstack/src/main/java/org/apache/camel/component/openstack/cinder/CinderComponent.java
----------------------------------------------------------------------
diff --git a/components/camel-openstack/src/main/java/org/apache/camel/component/openstack/cinder/CinderComponent.java b/components/camel-openstack/src/main/java/org/apache/camel/component/openstack/cinder/CinderComponent.java
new file mode 100644
index 0000000..2baaa7a
--- /dev/null
+++ b/components/camel-openstack/src/main/java/org/apache/camel/component/openstack/cinder/CinderComponent.java
@@ -0,0 +1,32 @@
+/**
+ * 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.openstack.cinder;
+
+import org.apache.camel.Endpoint;
+import org.apache.camel.impl.DefaultComponent;
+
+import java.util.Map;
+
+public class CinderComponent extends DefaultComponent {
+
+	@Override protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
+		CinderEndpoint endpoint = new CinderEndpoint(uri, this);
+		setProperties(endpoint, parameters);
+		endpoint.setHost(remaining);
+		return endpoint;
+	}
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/fd9e822a/components/camel-openstack/src/main/java/org/apache/camel/component/openstack/cinder/CinderConstants.java
----------------------------------------------------------------------
diff --git a/components/camel-openstack/src/main/java/org/apache/camel/component/openstack/cinder/CinderConstants.java b/components/camel-openstack/src/main/java/org/apache/camel/component/openstack/cinder/CinderConstants.java
new file mode 100644
index 0000000..e78cb12
--- /dev/null
+++ b/components/camel-openstack/src/main/java/org/apache/camel/component/openstack/cinder/CinderConstants.java
@@ -0,0 +1,23 @@
+package org.apache.camel.component.openstack.cinder;
+
+import org.apache.camel.component.openstack.common.OpenstackConstants;
+
+public final class CinderConstants extends OpenstackConstants{
+
+	public static final String VOLUMES = "volumes";
+	public static final String SNAPSHOTS = "snapshots";
+
+	//volumes
+	public static final String SIZE = "size";
+	public static final String VOLUME_TYPE = "volumeType";
+	public static final String IMAGE_REF = "imageRef";
+	public static final String SNAPSHOT_ID = "snapshotId";
+	public static final String IS_BOOTABLE = "isBootable";
+
+	//volumeSnapshots
+	public static final String VOLUME_ID = "volumeId";
+	public static final String FORCE = "force";
+
+	public static final String GET_ALL_TYPES = "getAllTypes";
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/fd9e822a/components/camel-openstack/src/main/java/org/apache/camel/component/openstack/cinder/CinderEndpoint.java
----------------------------------------------------------------------
diff --git a/components/camel-openstack/src/main/java/org/apache/camel/component/openstack/cinder/CinderEndpoint.java b/components/camel-openstack/src/main/java/org/apache/camel/component/openstack/cinder/CinderEndpoint.java
new file mode 100644
index 0000000..721a815
--- /dev/null
+++ b/components/camel-openstack/src/main/java/org/apache/camel/component/openstack/cinder/CinderEndpoint.java
@@ -0,0 +1,158 @@
+/**
+ * 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.openstack.cinder;
+
+import org.apache.camel.Producer;
+import org.apache.camel.component.openstack.cinder.producer.SnapshotProducer;
+import org.apache.camel.component.openstack.cinder.producer.VolumeProducer;
+import org.apache.camel.component.openstack.common.AbstractOpenstackEndpoint;
+import org.apache.camel.spi.Metadata;
+import org.apache.camel.spi.UriEndpoint;
+import org.apache.camel.spi.UriParam;
+import org.apache.camel.spi.UriPath;
+
+@UriEndpoint(scheme = "openstack-cinder", title = "OpenStack-Cinder", syntax = "openstack-cinder:host", label = "cloud, virtualization")
+public class CinderEndpoint extends AbstractOpenstackEndpoint {
+
+	@UriPath
+	@Metadata(required = "true")
+	private String host;
+
+	@UriParam(defaultValue = "default")
+	private String domain = "default";
+
+	@UriParam(enums = "snapshots, volumes")
+	@Metadata(required = "true")
+	String subsystem;
+
+	@UriParam
+	@Metadata(required = "true")
+	private String project;
+
+	@UriParam
+	private String operation;
+
+	@UriParam
+	@Metadata(required = "true")
+	private String username;
+
+	@UriParam
+	@Metadata(required = "true")
+	private String password;
+
+	public CinderEndpoint(String uri, CinderComponent component) {
+		super(uri, component);
+
+	}
+
+	@Override
+	public Producer createProducer() throws Exception {
+		switch (getSubsystem()) {
+			case CinderConstants.VOLUMES:
+				return new VolumeProducer(this, createClient());
+			case CinderConstants.SNAPSHOTS:
+				return new SnapshotProducer(this, createClient());
+			default:
+				throw new IllegalArgumentException("Can't create producer with subsystem " + subsystem);
+		}
+	}
+
+	public String getSubsystem() {
+		return subsystem;
+	}
+
+	/**
+	 * OpenStack Nova subsystem
+	 */
+	public void setSubsystem(String subsystem) {
+		this.subsystem = subsystem;
+	}
+
+	@Override
+	public String getDomain() {
+		return domain;
+	}
+
+	/**
+	 * Authentication domain
+	 */
+	public void setDomain(String domain) {
+		this.domain = domain;
+	}
+
+	@Override
+	public String getProject() {
+		return project;
+	}
+
+	/**
+	 * The project ID
+	 */
+	public void setProject(String project) {
+		this.project = project;
+	}
+
+	@Override
+	public String getOperation() {
+		return operation;
+	}
+
+	/**
+	 * The operation to do
+	 */
+	public void setOperation(String operation) {
+		this.operation = operation;
+	}
+
+	@Override
+	public String getUsername() {
+		return username;
+	}
+
+	/**
+	 * OpenStack username
+	 */
+	public void setUsername(String username) {
+		this.username = username;
+	}
+
+	@Override
+	public String getPassword() {
+		return password;
+	}
+
+	/**
+	 * OpenStack password
+	 */
+	public void setPassword(String password) {
+		this.password = password;
+	}
+
+	@Override
+	public String getHost() {
+		return host;
+	}
+
+	/**
+	 * OpenStack host url
+	 */
+	public void setHost(String host) {
+		this.host = host;
+	}
+}
+
+

http://git-wip-us.apache.org/repos/asf/camel/blob/fd9e822a/components/camel-openstack/src/main/java/org/apache/camel/component/openstack/cinder/producer/SnapshotProducer.java
----------------------------------------------------------------------
diff --git a/components/camel-openstack/src/main/java/org/apache/camel/component/openstack/cinder/producer/SnapshotProducer.java b/components/camel-openstack/src/main/java/org/apache/camel/component/openstack/cinder/producer/SnapshotProducer.java
new file mode 100644
index 0000000..85bc79b
--- /dev/null
+++ b/components/camel-openstack/src/main/java/org/apache/camel/component/openstack/cinder/producer/SnapshotProducer.java
@@ -0,0 +1,129 @@
+/**
+ * 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.openstack.cinder.producer;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Message;
+import org.apache.camel.component.openstack.cinder.CinderConstants;
+import org.apache.camel.component.openstack.cinder.CinderEndpoint;
+import org.apache.camel.component.openstack.common.AbstractOpenstackProducer;
+import org.apache.camel.util.ObjectHelper;
+
+import org.openstack4j.api.Builders;
+import org.openstack4j.api.OSClient;
+import org.openstack4j.model.common.ActionResponse;
+import org.openstack4j.model.storage.block.VolumeSnapshot;
+import org.openstack4j.model.storage.block.builder.VolumeSnapshotBuilder;
+
+import java.util.List;
+import java.util.Map;
+
+public class SnapshotProducer extends AbstractOpenstackProducer {
+
+	public SnapshotProducer(CinderEndpoint endpoint, OSClient client) {
+		super(endpoint, client);
+	}
+
+	@Override
+	public void process(Exchange exchange) throws Exception {
+		String operation = getOperation(exchange);
+
+		switch (operation) {
+			case CinderConstants.CREATE:
+				doCreate(exchange);
+				break;
+			case CinderConstants.GET:
+				doGet(exchange);
+				break;
+			case CinderConstants.GET_ALL:
+				doGetAll(exchange);
+				break;
+			case CinderConstants.UPDATE:
+				doUpdate(exchange);
+				break;
+			case CinderConstants.DELETE:
+				doDelete(exchange);
+				break;
+			default:
+				throw new IllegalArgumentException("Unsupported operation " + operation);
+		}
+	}
+
+	private void doCreate(Exchange exchange) {
+		final Message msg = exchange.getIn();
+		final VolumeSnapshot in = messageToSnapshot(msg);
+		final VolumeSnapshot out = os.blockStorage().snapshots().create(in);
+		msg.setBody(out);
+	}
+
+	private void doGet(Exchange exchange) {
+		final Message msg = exchange.getIn();
+		final String id = msg.getHeader(CinderConstants.ID, msg.getHeader(CinderConstants.SNAPSHOT_ID, String.class), String.class);
+		ObjectHelper.notEmpty(id, "Snapshot ID");
+		final VolumeSnapshot out = os.blockStorage().snapshots().get(id);
+		msg.setBody(out);
+	}
+
+	private void doGetAll(Exchange exchange) {
+		final List<? extends VolumeSnapshot> out = os.blockStorage().snapshots().list();
+		exchange.getIn().setBody(out);
+	}
+
+	private void doUpdate(Exchange exchange) {
+		final Message msg = exchange.getIn();
+		final String id = msg.getHeader(CinderConstants.ID, msg.getHeader(CinderConstants.SNAPSHOT_ID, String.class), String.class);
+		final VolumeSnapshot vs = messageToSnapshot(msg);
+		ObjectHelper.notEmpty(id, "Cinder Snapshot ID");
+
+		final ActionResponse out = os.blockStorage().snapshots().update(id, vs.getName(), vs.getDescription());
+		checkFailure(out, msg, "Update volume snapshot " + id);
+	}
+
+	private void doDelete(Exchange exchange) {
+		final Message msg = exchange.getIn();
+		final String id = msg.getHeader(CinderConstants.ID, msg.getHeader(CinderConstants.SNAPSHOT_ID, String.class), String.class);
+		ObjectHelper.notEmpty(id, "Cinder Snapshot ID");
+
+		final ActionResponse out = os.blockStorage().snapshots().delete(id);
+		checkFailure(out, msg, "Delete snapshot " + id);
+	}
+
+	private VolumeSnapshot messageToSnapshot(Message message) {
+		VolumeSnapshot volume = message.getBody(VolumeSnapshot.class);
+		if (volume == null) {
+			Map headers = message.getHeaders();
+			VolumeSnapshotBuilder builder = Builders.volumeSnapshot();
+
+			final String name = message.getHeader(CinderConstants.NAME, String.class);
+			ObjectHelper.notEmpty(name, "Name");
+			builder.name(name);
+
+			if(headers.containsKey(CinderConstants.DESCRIPTION))
+			builder.description(message.getHeader(CinderConstants.DESCRIPTION, String.class));
+
+			if(headers.containsKey(CinderConstants.VOLUME_ID))
+			builder.volume(message.getHeader(CinderConstants.VOLUME_ID, String.class));
+
+			if(headers.containsKey(CinderConstants.FORCE))
+			builder.force(message.getHeader(CinderConstants.FORCE, Boolean.class));
+
+			volume = builder.build();
+		}
+
+		return volume;
+	}
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/fd9e822a/components/camel-openstack/src/main/java/org/apache/camel/component/openstack/cinder/producer/VolumeProducer.java
----------------------------------------------------------------------
diff --git a/components/camel-openstack/src/main/java/org/apache/camel/component/openstack/cinder/producer/VolumeProducer.java b/components/camel-openstack/src/main/java/org/apache/camel/component/openstack/cinder/producer/VolumeProducer.java
new file mode 100644
index 0000000..22163e7
--- /dev/null
+++ b/components/camel-openstack/src/main/java/org/apache/camel/component/openstack/cinder/producer/VolumeProducer.java
@@ -0,0 +1,148 @@
+/**
+ * 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.openstack.cinder.producer;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Message;
+import org.apache.camel.component.openstack.cinder.CinderConstants;
+import org.apache.camel.component.openstack.cinder.CinderEndpoint;
+import org.apache.camel.component.openstack.common.AbstractOpenstackProducer;
+import org.apache.camel.util.ObjectHelper;
+
+import org.openstack4j.api.Builders;
+import org.openstack4j.api.OSClient;
+import org.openstack4j.model.common.ActionResponse;
+import org.openstack4j.model.storage.block.Volume;
+import org.openstack4j.model.storage.block.VolumeType;
+import org.openstack4j.model.storage.block.builder.VolumeBuilder;
+
+import java.util.List;
+import java.util.Map;
+
+public class VolumeProducer extends AbstractOpenstackProducer {
+
+	public VolumeProducer(CinderEndpoint endpoint, OSClient client) {
+		super(endpoint, client);
+	}
+
+	@Override
+	public void process(Exchange exchange) throws Exception {
+		String operation = getOperation(exchange);
+
+		switch (operation) {
+			case CinderConstants.CREATE:
+				doCreate(exchange);
+				break;
+			case CinderConstants.GET:
+				doGet(exchange);
+				break;
+			case CinderConstants.GET_ALL:
+				doGetAll(exchange);
+				break;
+			case CinderConstants.GET_ALL_TYPES:
+				doGetAllTypes(exchange);
+				break;
+			case CinderConstants.UPDATE:
+				doUpdate(exchange);
+				break;
+			case CinderConstants.DELETE:
+				doDelete(exchange);
+				break;
+			default:
+				throw new IllegalArgumentException("Unsupported operation " + operation);
+		}
+	}
+
+	private void doCreate(Exchange exchange) {
+		final Message msg = exchange.getIn();
+		final Volume in = messageToVolume(msg);
+		final Volume out = os.blockStorage().volumes().create(in);
+		msg.setBody(out);
+	}
+
+	private void doGet(Exchange exchange) {
+		final Message msg = exchange.getIn();
+		final String id = msg.getHeader(CinderConstants.ID, msg.getHeader(CinderConstants.VOLUME_ID, String.class), String.class);
+		ObjectHelper.notEmpty(id, "Volume ID");
+		final Volume out = os.blockStorage().volumes().get(id);
+		msg.setBody(out);
+	}
+
+	private void doGetAll(Exchange exchange) {
+		final List<? extends Volume> out = os.blockStorage().volumes().list();
+		exchange.getIn().setBody(out);
+	}
+
+	private void doGetAllTypes(Exchange exchange) {
+		final List<? extends VolumeType> out = os.blockStorage().volumes().listVolumeTypes();
+		exchange.getIn().setBody(out);
+	}
+
+	private void doUpdate(Exchange exchange) {
+		final Message msg = exchange.getIn();
+		final String id = msg.getHeader(CinderConstants.ID, msg.getHeader(CinderConstants.VOLUME_ID, String.class), String.class);
+		final Volume vol = messageToVolume(msg);
+		;
+		ObjectHelper.notEmpty(id, "Cinder Volume ID");
+		ObjectHelper.notEmpty(vol.getDescription(), "Cinder Volume Description");
+		ObjectHelper.notEmpty(vol.getName(), "Cinder Volume Name");
+		final ActionResponse out = os.blockStorage().volumes().update(id, vol.getName(), vol.getDescription());
+		checkFailure(out, msg, "Update volume " + id);
+	}
+
+	private void doDelete(Exchange exchange) {
+		final Message msg = exchange.getIn();
+		final String id = msg.getHeader(CinderConstants.ID, msg.getHeader(CinderConstants.VOLUME_ID, String.class), String.class);
+		ObjectHelper.notEmpty(id, "Cinder Volume ID");
+		final ActionResponse out = os.blockStorage().volumes().delete(id);
+		checkFailure(out, msg, "Delete volume " + id);
+	}
+
+	private Volume messageToVolume(Message message) {
+		Volume volume = message.getBody(Volume.class);
+		if (volume == null) {
+			Map headers = message.getHeaders();
+			VolumeBuilder builder = Builders.volume();
+
+			final String name = message.getHeader(CinderConstants.NAME, String.class);
+			ObjectHelper.notEmpty(name, "Name ");
+			builder.name(name);
+
+			if (headers.containsKey(CinderConstants.DESCRIPTION))
+				builder.description(message.getHeader(CinderConstants.DESCRIPTION, String.class));
+
+			if (headers.containsKey(CinderConstants.SIZE))
+				builder.size(message.getHeader(CinderConstants.SIZE, Integer.class));
+
+			if (headers.containsKey(CinderConstants.VOLUME_TYPE))
+				builder.volumeType(message.getHeader(CinderConstants.VOLUME_TYPE, String.class));
+
+			if (headers.containsKey(CinderConstants.IMAGE_REF))
+				builder.imageRef(message.getHeader(CinderConstants.IMAGE_REF, String.class));
+
+			if (headers.containsKey(CinderConstants.SNAPSHOT_ID))
+				builder.snapshot(message.getHeader(CinderConstants.SNAPSHOT_ID, String.class));
+
+			if (headers.containsKey(CinderConstants.IS_BOOTABLE))
+				builder.bootable(message.getHeader(CinderConstants.IS_BOOTABLE, Boolean.class));
+
+			volume = builder.build();
+		}
+
+		return volume;
+	}
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/fd9e822a/components/camel-openstack/src/main/resources/META-INF/services/org/apache/camel/component/openstack-cinder
----------------------------------------------------------------------
diff --git a/components/camel-openstack/src/main/resources/META-INF/services/org/apache/camel/component/openstack-cinder b/components/camel-openstack/src/main/resources/META-INF/services/org/apache/camel/component/openstack-cinder
new file mode 100644
index 0000000..20c55ab
--- /dev/null
+++ b/components/camel-openstack/src/main/resources/META-INF/services/org/apache/camel/component/openstack-cinder
@@ -0,0 +1 @@
+class=org.apache.camel.component.openstack.cinder.CinderComponent

http://git-wip-us.apache.org/repos/asf/camel/blob/fd9e822a/components/camel-openstack/src/test/java/org/apache/camel/component/openstack/cinder/CinderProducerTestSupport.java
----------------------------------------------------------------------
diff --git a/components/camel-openstack/src/test/java/org/apache/camel/component/openstack/cinder/CinderProducerTestSupport.java b/components/camel-openstack/src/test/java/org/apache/camel/component/openstack/cinder/CinderProducerTestSupport.java
new file mode 100644
index 0000000..b6bc939
--- /dev/null
+++ b/components/camel-openstack/src/test/java/org/apache/camel/component/openstack/cinder/CinderProducerTestSupport.java
@@ -0,0 +1,50 @@
+/**
+ * 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.openstack.cinder;
+
+import static org.mockito.Mockito.when;
+
+import org.apache.camel.component.openstack.AbstractProducerTestSupport;
+
+import org.junit.Before;
+
+import org.mockito.Mock;
+import org.openstack4j.api.storage.BlockStorageService;
+import org.openstack4j.api.storage.BlockVolumeService;
+import org.openstack4j.api.storage.BlockVolumeSnapshotService;
+
+public class CinderProducerTestSupport extends AbstractProducerTestSupport {
+
+	@Mock
+	protected CinderEndpoint endpoint;
+
+	@Mock
+	protected BlockStorageService blockStorageService;
+
+	@Mock
+	protected BlockVolumeService volumeService;
+
+	@Mock
+	protected BlockVolumeSnapshotService snapshotService;
+
+	@Before
+	public void setUpComputeService(){
+		when(client.blockStorage()).thenReturn(blockStorageService);
+		when(blockStorageService.volumes()).thenReturn(volumeService);
+		when(blockStorageService.snapshots()).thenReturn(snapshotService);
+	}
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/fd9e822a/components/camel-openstack/src/test/java/org/apache/camel/component/openstack/cinder/VolumeProducerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-openstack/src/test/java/org/apache/camel/component/openstack/cinder/VolumeProducerTest.java b/components/camel-openstack/src/test/java/org/apache/camel/component/openstack/cinder/VolumeProducerTest.java
new file mode 100644
index 0000000..8464cae
--- /dev/null
+++ b/components/camel-openstack/src/test/java/org/apache/camel/component/openstack/cinder/VolumeProducerTest.java
@@ -0,0 +1,159 @@
+/**
+ * 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.openstack.cinder;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import static org.mockito.Matchers.anyString;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import org.apache.camel.component.openstack.cinder.producer.VolumeProducer;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import org.mockito.ArgumentCaptor;
+import org.mockito.Matchers;
+import org.mockito.Mock;
+import org.openstack4j.api.Builders;
+import org.openstack4j.model.common.ActionResponse;
+import org.openstack4j.model.storage.block.Volume;
+import org.openstack4j.model.storage.block.builder.VolumeBuilder;
+
+import java.util.UUID;
+
+public class VolumeProducerTest extends CinderProducerTestSupport {
+
+	@Mock
+	private Volume testOSVolume;
+
+	private Volume dummyVolume;
+
+	@Before
+	public void setUp() {
+		producer = new VolumeProducer(endpoint, client);
+
+		when(volumeService.create(Matchers.any(org.openstack4j.model.storage.block.Volume.class))).thenReturn(testOSVolume);
+		when(volumeService.get(Matchers.anyString())).thenReturn(testOSVolume);
+
+		dummyVolume = createTestVolume();
+		when(testOSVolume.getId()).thenReturn(UUID.randomUUID().toString());
+		when(testOSVolume.getName()).thenReturn(dummyVolume.getName());
+		when(testOSVolume.getDescription()).thenReturn(dummyVolume.getDescription());
+		when(testOSVolume.getImageRef()).thenReturn(dummyVolume.getImageRef());
+		when(testOSVolume.getSize()).thenReturn(dummyVolume.getSize());
+		when(testOSVolume.getVolumeType()).thenReturn(dummyVolume.getVolumeType());
+	}
+
+	@Test
+	public void createVolumeTest() throws Exception {
+		when(endpoint.getOperation()).thenReturn(CinderConstants.CREATE);
+		msg.setBody(dummyVolume);
+		producer.process(exchange);
+		assertEqualVolumes(dummyVolume, msg.getBody(Volume.class));
+	}
+
+	@Test
+	public void updateVolumeTest() throws Exception {
+		when(volumeService.update(anyString(), anyString(), anyString())).thenReturn(ActionResponse.actionSuccess());
+		msg.setHeader(CinderConstants.OPERATION, CinderConstants.UPDATE);
+		final String id = "id";
+		final String desc = "newDesc";
+		final String name = "newName";
+		msg.setHeader(CinderConstants.ID, id);
+		msg.setHeader(CinderConstants.DESCRIPTION, desc);
+		msg.setHeader(CinderConstants.NAME, name);
+
+		producer.process(exchange);
+
+		ArgumentCaptor<String> idCaptor = ArgumentCaptor.forClass(String.class);
+		ArgumentCaptor<String> nameCaptor = ArgumentCaptor.forClass(String.class);
+		ArgumentCaptor<String> descCaptor = ArgumentCaptor.forClass(String.class);
+		verify(volumeService).update(idCaptor.capture(), nameCaptor.capture(), descCaptor.capture());
+
+		assertEquals(id, idCaptor.getValue());
+		assertEquals(name, nameCaptor.getValue());
+		assertEquals(desc, descCaptor.getValue());
+		assertFalse(msg.isFault());
+		assertNull(msg.getBody());
+	}
+
+	@Test
+	public void updateVolumeFailTest() throws Exception {
+		final String faultMessage = "fault";
+		when(volumeService.update(anyString(), anyString(), anyString())).thenReturn(ActionResponse.actionFailed(faultMessage, 401));
+
+		msg.setHeader(CinderConstants.OPERATION, CinderConstants.UPDATE);
+		final String id = "id";
+		msg.setHeader(CinderConstants.ID, id);
+		msg.setBody(createTestVolume());
+
+		producer.process(exchange);
+
+		assertTrue(msg.isFault());
+		assertTrue(msg.getBody(String.class).contains(faultMessage));
+	}
+
+	@Test
+	public void getVolumeTest() throws Exception {
+		when(endpoint.getOperation()).thenReturn(CinderConstants.GET);
+		msg.setHeader(CinderConstants.ID, "anyID");
+		producer.process(exchange);
+
+		assertEqualVolumes(dummyVolume, msg.getBody(Volume.class));
+	}
+
+	@Test
+	public void deleteVolumeTest() throws Exception {
+		msg.setHeader(CinderConstants.OPERATION, CinderConstants.DELETE);
+		when(volumeService.delete(anyString())).thenReturn(ActionResponse.actionSuccess());
+		final String id = "id";
+		msg.setHeader(CinderConstants.ID, id);
+
+		producer.process(exchange);
+
+		ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
+		verify(volumeService).delete(captor.capture());
+		assertEquals(id, captor.getValue());
+
+		assertFalse(msg.isFault());
+	}
+
+	private void assertEqualVolumes(Volume old, Volume newVolume) {
+		assertEquals(old.getName(), newVolume.getName());
+		assertEquals(old.getDescription(), newVolume.getDescription());
+		assertEquals(old.getImageRef(), newVolume.getImageRef());
+		assertEquals(old.getSize(), newVolume.getSize());
+		assertEquals(old.getVolumeType(), newVolume.getVolumeType());
+
+		assertNotNull(newVolume.getId());
+	}
+
+	private Volume createTestVolume() {
+		VolumeBuilder builder = Builders.volume()
+				.name("name")
+				.description("description")
+				.imageRef("ref").size(20)
+				.volumeType("type");
+		return builder.build();
+	}
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/fd9e822a/components/camel-openstack/src/test/java/org/apache/camel/component/openstack/cinder/VolumeSnapshotProducerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-openstack/src/test/java/org/apache/camel/component/openstack/cinder/VolumeSnapshotProducerTest.java b/components/camel-openstack/src/test/java/org/apache/camel/component/openstack/cinder/VolumeSnapshotProducerTest.java
new file mode 100644
index 0000000..3173f1a
--- /dev/null
+++ b/components/camel-openstack/src/test/java/org/apache/camel/component/openstack/cinder/VolumeSnapshotProducerTest.java
@@ -0,0 +1,136 @@
+/**
+ * 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.openstack.cinder;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+
+import static org.mockito.Matchers.anyString;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import org.apache.camel.component.openstack.cinder.producer.SnapshotProducer;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import org.mockito.ArgumentCaptor;
+import org.mockito.Matchers;
+import org.mockito.Mock;
+import org.openstack4j.api.Builders;
+import org.openstack4j.model.common.ActionResponse;
+import org.openstack4j.model.storage.block.VolumeSnapshot;
+
+import java.util.UUID;
+
+public class VolumeSnapshotProducerTest extends CinderProducerTestSupport {
+
+	@Mock
+	private VolumeSnapshot testOSVolumeSnapshot;
+
+	private VolumeSnapshot dummyVolumeSnapshot;
+
+	@Before
+	public void setUp() {
+		producer = new SnapshotProducer(endpoint, client);
+
+		when(snapshotService.create(Matchers.any(VolumeSnapshot.class))).thenReturn(testOSVolumeSnapshot);
+		when(snapshotService.get(Matchers.anyString())).thenReturn(testOSVolumeSnapshot);
+
+		dummyVolumeSnapshot = createTestVolume();
+		when(testOSVolumeSnapshot.getId()).thenReturn(UUID.randomUUID().toString());
+		when(testOSVolumeSnapshot.getName()).thenReturn(dummyVolumeSnapshot.getName());
+		when(testOSVolumeSnapshot.getDescription()).thenReturn(dummyVolumeSnapshot.getDescription());
+		when(testOSVolumeSnapshot.getVolumeId()).thenReturn(dummyVolumeSnapshot.getVolumeId());
+	}
+
+	@Test
+	public void createVolumeTest() throws Exception {
+		when(endpoint.getOperation()).thenReturn(CinderConstants.CREATE);
+		msg.setBody(dummyVolumeSnapshot);
+		producer.process(exchange);
+		final VolumeSnapshot result = msg.getBody(VolumeSnapshot.class);
+		assertEqualsVolumeSnapshots(dummyVolumeSnapshot, result);
+		assertNotNull(result.getId());
+	}
+
+	@Test
+	public void updateVolumeSnapshotTest() throws Exception {
+		when(snapshotService.update(anyString(), anyString(), anyString())).thenReturn(ActionResponse.actionSuccess());
+		msg.setHeader(CinderConstants.OPERATION, CinderConstants.UPDATE);
+		final String id = "id";
+		final String desc = "newDesc";
+		final String name = "newName";
+		msg.setHeader(CinderConstants.ID, id);
+		msg.setHeader(CinderConstants.DESCRIPTION, desc);
+		msg.setHeader(CinderConstants.NAME, name);
+
+		producer.process(exchange);
+
+		ArgumentCaptor<String> idCaptor = ArgumentCaptor.forClass(String.class);
+		ArgumentCaptor<String> nameCaptor = ArgumentCaptor.forClass(String.class);
+		ArgumentCaptor<String> descCaptor = ArgumentCaptor.forClass(String.class);
+		verify(snapshotService).update(idCaptor.capture(), nameCaptor.capture(), descCaptor.capture());
+
+		assertEquals(id, idCaptor.getValue());
+		assertEquals(name, nameCaptor.getValue());
+		assertEquals(desc, descCaptor.getValue());
+		assertFalse(msg.isFault());
+		assertNull(msg.getBody());
+	}
+
+
+	@Test
+	public void getVolumeSnapshotTest() throws Exception {
+		when(endpoint.getOperation()).thenReturn(CinderConstants.GET);
+		msg.setHeader(CinderConstants.ID, "anyID");
+		producer.process(exchange);
+
+		assertEqualsVolumeSnapshots(dummyVolumeSnapshot, msg.getBody(VolumeSnapshot.class));
+	}
+
+	@Test
+	public void deleteVolumeSnapshotTest() throws Exception {
+		msg.setHeader(CinderConstants.OPERATION, CinderConstants.DELETE);
+		when(snapshotService.delete(anyString())).thenReturn(ActionResponse.actionSuccess());
+		final String id = "id";
+		msg.setHeader(CinderConstants.ID, id);
+
+		producer.process(exchange);
+
+		ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
+		verify(snapshotService).delete(captor.capture());
+		assertEquals(id, captor.getValue());
+		assertFalse(msg.isFault());
+	}
+
+	private void assertEqualsVolumeSnapshots(VolumeSnapshot old, VolumeSnapshot newVolumeSn) {
+		assertEquals(old.getName(), newVolumeSn.getName());
+		assertEquals(old.getDescription(), newVolumeSn.getDescription());
+		assertEquals(old.getVolumeId(), newVolumeSn.getVolumeId());
+	}
+
+	private VolumeSnapshot createTestVolume() {
+		return Builders.volumeSnapshot()
+				.description("descr")
+				.name("name")
+				.volume("volId")
+				.build();
+	}
+}