incubator-nuvem-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sag...@apache.org
Subject svn commit: r1161611 - in /incubator/nuvem/trunk: ./ nuvem-amazon/ nuvem-amazon/src/ nuvem-amazon/src/main/ nuvem-amazon/src/main/java/ nuvem-amazon/src/main/java/org/ nuvem-amazon/src/main/java/org/apache/ nuvem-amazon/src/main/java/org/apache/nuvem/ ...
Date Thu, 25 Aug 2011 15:46:03 GMT
Author: sagara
Date: Thu Aug 25 15:46:02 2011
New Revision: 1161611

URL: http://svn.apache.org/viewvc?rev=1161611&view=rev
Log:
Applied latest patch for NUVEM-9.

Added:
    incubator/nuvem/trunk/nuvem-amazon/
    incubator/nuvem/trunk/nuvem-amazon/pom.xml   (with props)
    incubator/nuvem/trunk/nuvem-amazon/src/
    incubator/nuvem/trunk/nuvem-amazon/src/main/
    incubator/nuvem/trunk/nuvem-amazon/src/main/java/
    incubator/nuvem/trunk/nuvem-amazon/src/main/java/org/
    incubator/nuvem/trunk/nuvem-amazon/src/main/java/org/apache/
    incubator/nuvem/trunk/nuvem-amazon/src/main/java/org/apache/nuvem/
    incubator/nuvem/trunk/nuvem-amazon/src/main/java/org/apache/nuvem/cloud/
    incubator/nuvem/trunk/nuvem-amazon/src/main/java/org/apache/nuvem/cloud/dataService/
    incubator/nuvem/trunk/nuvem-amazon/src/main/java/org/apache/nuvem/cloud/dataService/impl/
    incubator/nuvem/trunk/nuvem-amazon/src/main/java/org/apache/nuvem/cloud/dataService/impl/AmazonDataServiceImpl.java   (with props)
    incubator/nuvem/trunk/nuvem-amazon/src/main/resources/
    incubator/nuvem/trunk/nuvem-amazon/src/test/
    incubator/nuvem/trunk/nuvem-amazon/src/test/java/
    incubator/nuvem/trunk/nuvem-amazon/src/test/java/org/
    incubator/nuvem/trunk/nuvem-amazon/src/test/java/org/apache/
    incubator/nuvem/trunk/nuvem-amazon/src/test/java/org/apache/nuvem/
    incubator/nuvem/trunk/nuvem-amazon/src/test/java/org/apache/nuvem/cloud/
    incubator/nuvem/trunk/nuvem-amazon/src/test/java/org/apache/nuvem/cloud/dataService/
    incubator/nuvem/trunk/nuvem-amazon/src/test/java/org/apache/nuvem/cloud/dataService/impl/
    incubator/nuvem/trunk/nuvem-amazon/src/test/java/org/apache/nuvem/cloud/dataService/impl/AmazonDataServiceClientFactory.java   (with props)
    incubator/nuvem/trunk/nuvem-amazon/src/test/java/org/apache/nuvem/cloud/dataService/impl/AmazonDataServiceImplTestCase.java   (with props)
    incubator/nuvem/trunk/nuvem-amazon/src/test/java/org/apache/nuvem/cloud/dataService/impl/MockAmazonSimpleDBClient.java   (with props)
    incubator/nuvem/trunk/nuvem-amazon/src/test/resources/
    incubator/nuvem/trunk/nuvem-amazon/src/test/resources/test.properties   (with props)
    incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/dataService/DataServiceUtil.java   (with props)
    incubator/nuvem/trunk/nuvem-google/src/test/java/org/apache/nuvem/cloud/dataService/impl/GoogleDataServiceImplTestCase.java
      - copied, changed from r1152431, incubator/nuvem/trunk/nuvem-google/src/test/java/org/apache/nuvem/cloud/dataService/impl/GoogleDataServiceImplTest.java
    incubator/nuvem/trunk/nuvem-standalone/src/main/java/org/apache/nuvem/cloud/dataService/
    incubator/nuvem/trunk/nuvem-standalone/src/main/java/org/apache/nuvem/cloud/dataService/impl/
    incubator/nuvem/trunk/nuvem-standalone/src/main/java/org/apache/nuvem/cloud/dataService/impl/CassandraDataServiceImpl.java   (with props)
    incubator/nuvem/trunk/nuvem-standalone/src/test/java/org/apache/nuvem/cloud/dataService/
    incubator/nuvem/trunk/nuvem-standalone/src/test/java/org/apache/nuvem/cloud/dataService/impl/
    incubator/nuvem/trunk/nuvem-standalone/src/test/java/org/apache/nuvem/cloud/dataService/impl/CassandraDataServiceImplTestCase.java   (with props)
Removed:
    incubator/nuvem/trunk/nuvem-google/src/test/java/org/apache/nuvem/cloud/dataService/impl/GoogleDataServiceImplTest.java
Modified:
    incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/dataService/DataService.java
    incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/dataService/Element.java
    incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/dataService/Feature.java
    incubator/nuvem/trunk/nuvem-google/src/main/java/org/apache/nuvem/cloud/dataService/impl/GoogleDataServiceImpl.java
    incubator/nuvem/trunk/nuvem-standalone/pom.xml
    incubator/nuvem/trunk/pom.xml

Added: incubator/nuvem/trunk/nuvem-amazon/pom.xml
URL: http://svn.apache.org/viewvc/incubator/nuvem/trunk/nuvem-amazon/pom.xml?rev=1161611&view=auto
==============================================================================
--- incubator/nuvem/trunk/nuvem-amazon/pom.xml (added)
+++ incubator/nuvem/trunk/nuvem-amazon/pom.xml Thu Aug 25 15:46:02 2011
@@ -0,0 +1,46 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- * 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. -->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+	<modelVersion>4.0.0</modelVersion>
+	<parent>
+		<groupId>org.apache.nuvem</groupId>
+		<artifactId>nuvem</artifactId>
+		<version>1.0-incubating-SNAPSHOT</version>
+		<relativePath>../pom.xml</relativePath>
+	</parent>
+	<artifactId>nuvem-amazon</artifactId>
+	<version>1.0-incubating-SNAPSHOT</version>
+	<name>Apache Nuvem Cloud API Implementation for Amazon Cloud</name>
+	<dependencies>
+		<dependency>
+			<groupId>org.apache.nuvem</groupId>
+			<artifactId>nuvem-api</artifactId>
+			<version>${project.version}</version>
+		</dependency>
+		<dependency>
+			<groupId>com.amazonaws</groupId>
+			<artifactId>aws-java-sdk</artifactId>
+			<version>1.1.5</version>
+		</dependency>
+
+		<dependency>
+			<groupId>junit</groupId>
+			<artifactId>junit</artifactId>
+			<version>4.8.1</version>
+			<scope>test</scope>
+		</dependency>
+
+	</dependencies>
+
+</project>

Propchange: incubator/nuvem/trunk/nuvem-amazon/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/nuvem/trunk/nuvem-amazon/src/main/java/org/apache/nuvem/cloud/dataService/impl/AmazonDataServiceImpl.java
URL: http://svn.apache.org/viewvc/incubator/nuvem/trunk/nuvem-amazon/src/main/java/org/apache/nuvem/cloud/dataService/impl/AmazonDataServiceImpl.java?rev=1161611&view=auto
==============================================================================
--- incubator/nuvem/trunk/nuvem-amazon/src/main/java/org/apache/nuvem/cloud/dataService/impl/AmazonDataServiceImpl.java (added)
+++ incubator/nuvem/trunk/nuvem-amazon/src/main/java/org/apache/nuvem/cloud/dataService/impl/AmazonDataServiceImpl.java Thu Aug 25 15:46:02 2011
@@ -0,0 +1,271 @@
+/*
+ * 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.nuvem.cloud.dataService.impl;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.nuvem.cloud.dataService.DataService;
+import org.apache.nuvem.cloud.dataService.DataServiceException;
+import org.apache.nuvem.cloud.dataService.DataServiceUtil;
+import org.apache.nuvem.cloud.dataService.Element;
+import org.apache.nuvem.cloud.dataService.Feature;
+
+import com.amazonaws.auth.AWSCredentials;
+import com.amazonaws.auth.PropertiesCredentials;
+import com.amazonaws.services.simpledb.AmazonSimpleDB;
+import com.amazonaws.services.simpledb.AmazonSimpleDBClient;
+import com.amazonaws.services.simpledb.model.BatchPutAttributesRequest;
+import com.amazonaws.services.simpledb.model.CreateDomainRequest;
+import com.amazonaws.services.simpledb.model.DeleteAttributesRequest;
+import com.amazonaws.services.simpledb.model.Item;
+import com.amazonaws.services.simpledb.model.ListDomainsResult;
+import com.amazonaws.services.simpledb.model.PutAttributesRequest;
+import com.amazonaws.services.simpledb.model.ReplaceableAttribute;
+import com.amazonaws.services.simpledb.model.ReplaceableItem;
+import com.amazonaws.services.simpledb.model.SelectRequest;
+import com.amazonaws.services.simpledb.model.SelectResult;
+import com.amazonaws.services.simpledb.model.Attribute;
+
+/**
+ * The Class AmazonDataServiceImpl is implementation of Nuvem DataService
+ * interface based on AmazonsimpleDB service. Element and Feature objects are
+ * mapped into GAE Entry and Properties.
+ */
+public class AmazonDataServiceImpl implements DataService {
+
+	private AmazonSimpleDB simpleDBClient;
+	private boolean isDefaultDomainExist;
+	private String domainName;
+
+	public AmazonDataServiceImpl() {
+		try {
+			isDefaultDomainExist = false;
+			domainName = AMAZON_DEFAULT_DOMAIN_NAME;
+			simpleDBClient = new AmazonSimpleDBClient(
+					new PropertiesCredentials(AmazonDataServiceImpl.class
+							.getResourceAsStream(AMAZON_CONFIG_FILE_NAME)));
+		} catch (IOException e) {
+			e.printStackTrace();
+		}
+	}
+
+	public AmazonDataServiceImpl(final String accessKey, final String secretKey) {
+		AWSCredentials credentials = new AWSCredentials() {
+			@Override
+			public String getAWSSecretKey() {
+				return secretKey;
+			}
+
+			@Override
+			public String getAWSAccessKeyId() {
+				return accessKey;
+			}
+		};
+
+		simpleDBClient = new AmazonSimpleDBClient(credentials);
+		domainName = AMAZON_DEFAULT_DOMAIN_NAME;
+	}
+
+	public AmazonDataServiceImpl(final Map config) {
+		AWSCredentials credentials = new AWSCredentials() {
+			@Override
+			public String getAWSSecretKey() {
+				return (String) config.get(AMAZON_SECRET_KEY);
+			}
+
+			@Override
+			public String getAWSAccessKeyId() {
+				return (String) config.get(AMAZON_ACCESS_KEY);
+			}
+		};
+		simpleDBClient = new AmazonSimpleDBClient(credentials);
+		domainName = AMAZON_DEFAULT_DOMAIN_NAME;
+
+	}
+
+	public AmazonDataServiceImpl(AmazonSimpleDBClient client) {
+		simpleDBClient = client;
+		domainName = AMAZON_DEFAULT_DOMAIN_NAME;
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see
+	 * org.apache.nuvem.cloud.dataService.DataService#createElement(org.apache
+	 * .nuvem.cloud.dataService.Element)
+	 */
+	@Override
+	public Element createElement(Element element) throws DataServiceException {
+		try {
+			createDomainIfNotExsist();
+			BatchPutAttributesRequest batchPutAttributesRequest = new BatchPutAttributesRequest();
+			batchPutAttributesRequest.setItems(getElementData(element));
+			batchPutAttributesRequest.setDomainName(domainName);
+			simpleDBClient.batchPutAttributes(batchPutAttributesRequest);
+			return element;
+		} catch (Exception e) {
+			throw new DataServiceException(e);
+		}
+	}
+
+	private List<ReplaceableItem> getElementData(Element element) {
+		List<ReplaceableItem> items = new ArrayList<ReplaceableItem>();
+		List<ReplaceableAttribute> attributes = new ArrayList<ReplaceableAttribute>();
+		for (Feature feature : element.getFeatures()) {
+			ReplaceableAttribute attribute = new ReplaceableAttribute(
+					feature.getName(), feature.getValue().toString(), true);
+			attributes.add(attribute);
+		}
+		ReplaceableItem elementItem = new ReplaceableItem(element.getKey())
+				.withAttributes(attributes);
+		items.add(elementItem);
+		return items;
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see
+	 * org.apache.nuvem.cloud.dataService.DataService#updateElement(org.apache
+	 * .nuvem.cloud.dataService.Element)
+	 */
+	@Override
+	public Element updateElement(Element element) throws DataServiceException {
+		try {
+			createDomainIfNotExsist();
+			List<ReplaceableAttribute> attributes = new ArrayList<ReplaceableAttribute>();
+			for (Feature feature : element.getFeatures()) {
+				ReplaceableAttribute attribute = new ReplaceableAttribute(
+						feature.getName(), feature.getValue().toString(), true);
+				attributes.add(attribute);
+			}
+			PutAttributesRequest putAttributesRequest = new PutAttributesRequest(
+					domainName, element.getKey(), attributes);
+			simpleDBClient.putAttributes((putAttributesRequest));
+			return element;
+		} catch (Exception e) {
+			throw new DataServiceException(e);
+		}
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see
+	 * org.apache.nuvem.cloud.dataService.DataService#getElement(java.lang.String
+	 * , java.lang.String)
+	 */
+	@Override
+	public Element getElement(String kind, String id)
+			throws DataServiceException {
+		try {
+			String itemName = DataServiceUtil.createKey(kind, id);
+			 String selectExpression = "select * from "+ domainName +
+			 " where itemName() in('"+ itemName+ "')";			
+			SelectRequest selectRequest = new SelectRequest();
+			selectRequest.setSelectExpression(selectExpression);
+			SelectResult selectResult = simpleDBClient.select(selectRequest);
+			List items = selectResult.getItems();
+			// Consider only first Item.
+			if (selectResult.getItems().size() == 0) {
+				return null;
+			}
+			Item item = selectResult.getItems().get(0);
+			if (item != null) {
+				String eleKind = DataServiceUtil.getKind(item.getName());
+				String eleId = DataServiceUtil.getId(item.getName());
+				Element element = new Element(eleKind);
+				element.setId(eleId);
+				element.setKey(item.getName());
+				element.setPersist();
+				Set<Feature> features = new HashSet<Feature>();
+				if (item.getAttributes() != null
+						&& item.getAttributes().size() > 0) {
+					for (Attribute att : item.getAttributes()) {
+						features.add(new Feature(att.getName(), att.getValue()));
+					}
+				}
+				element.setFeatures(features);
+				return element;
+			}
+			return null;
+		} catch (Exception e) {
+			throw new DataServiceException(e);
+		}
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see
+	 * org.apache.nuvem.cloud.dataService.DataService#deleteElement(org.apache
+	 * .nuvem.cloud.dataService.Element)
+	 */
+	@Override
+	public boolean deleteElement(Element element) throws DataServiceException {
+		try {
+			List<Attribute> attributes = new ArrayList<Attribute>();
+			for (Feature feature : element.getFeatures()) {
+				Attribute attribute = new Attribute(feature.getName(), feature
+						.getValue().toString());
+				attributes.add(attribute);
+			}
+			DeleteAttributesRequest deleteAttributesRequest = new DeleteAttributesRequest(
+					domainName, element.getKey(), attributes);
+			simpleDBClient.deleteAttributes(deleteAttributesRequest);
+			return true;
+
+		} catch (Exception e) {
+			throw new DataServiceException(e);
+		}
+
+	}
+
+	private void createDomainIfNotExsist() {
+		// Check default domain exists or not
+		if (isDefaultDomainExist) {
+			return;
+		}
+		ListDomainsResult listDomainsResult = simpleDBClient.listDomains();
+		for (String domainName : listDomainsResult.getDomainNames()) {
+			if (AMAZON_DEFAULT_DOMAIN_NAME.equals(domainName)) {
+				isDefaultDomainExist = true;
+				break;
+			}
+		}
+		if (!isDefaultDomainExist) {
+			CreateDomainRequest createDomainRequest = new CreateDomainRequest();
+			createDomainRequest.setDomainName(AMAZON_DEFAULT_DOMAIN_NAME);
+			simpleDBClient.createDomain(createDomainRequest);
+		}
+	}
+
+	public static final String AMAZON_CONFIG_FILE_NAME = "AwsCredentials.properties";
+	public static final String AMAZON_ACCESS_KEY = "accessKey";
+	public static final String AMAZON_SECRET_KEY = "secretKey";
+	public static final String AMAZON_DEFAULT_DOMAIN_NAME = "default";
+
+}

Propchange: incubator/nuvem/trunk/nuvem-amazon/src/main/java/org/apache/nuvem/cloud/dataService/impl/AmazonDataServiceImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/nuvem/trunk/nuvem-amazon/src/test/java/org/apache/nuvem/cloud/dataService/impl/AmazonDataServiceClientFactory.java
URL: http://svn.apache.org/viewvc/incubator/nuvem/trunk/nuvem-amazon/src/test/java/org/apache/nuvem/cloud/dataService/impl/AmazonDataServiceClientFactory.java?rev=1161611&view=auto
==============================================================================
--- incubator/nuvem/trunk/nuvem-amazon/src/test/java/org/apache/nuvem/cloud/dataService/impl/AmazonDataServiceClientFactory.java (added)
+++ incubator/nuvem/trunk/nuvem-amazon/src/test/java/org/apache/nuvem/cloud/dataService/impl/AmazonDataServiceClientFactory.java Thu Aug 25 15:46:02 2011
@@ -0,0 +1,48 @@
+/*
+ * 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.nuvem.cloud.dataService.impl;
+
+import com.amazonaws.AmazonWebServiceClient;
+import com.amazonaws.auth.AWSCredentials;
+import com.amazonaws.services.simpledb.AmazonSimpleDBClient;
+
+public class AmazonDataServiceClientFactory {
+
+	public static AmazonWebServiceClient getAmazonWebServiceClient(final String accessKey, final String secretKey) {	
+		
+		if(accessKey == null || secretKey == null){
+			return new MockAmazonSimpleDBClient();
+		}
+		
+		AWSCredentials credentials = new AWSCredentials() {
+			@Override
+			public String getAWSSecretKey() {
+				return secretKey;
+			}
+			@Override
+			public String getAWSAccessKeyId() {
+				return accessKey;
+			}
+		};
+		return  new AmazonSimpleDBClient(credentials);
+	}
+
+	
+}

Propchange: incubator/nuvem/trunk/nuvem-amazon/src/test/java/org/apache/nuvem/cloud/dataService/impl/AmazonDataServiceClientFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/nuvem/trunk/nuvem-amazon/src/test/java/org/apache/nuvem/cloud/dataService/impl/AmazonDataServiceImplTestCase.java
URL: http://svn.apache.org/viewvc/incubator/nuvem/trunk/nuvem-amazon/src/test/java/org/apache/nuvem/cloud/dataService/impl/AmazonDataServiceImplTestCase.java?rev=1161611&view=auto
==============================================================================
--- incubator/nuvem/trunk/nuvem-amazon/src/test/java/org/apache/nuvem/cloud/dataService/impl/AmazonDataServiceImplTestCase.java (added)
+++ incubator/nuvem/trunk/nuvem-amazon/src/test/java/org/apache/nuvem/cloud/dataService/impl/AmazonDataServiceImplTestCase.java Thu Aug 25 15:46:02 2011
@@ -0,0 +1,226 @@
+/*
+ * 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.nuvem.cloud.dataService.impl;
+
+import static org.junit.Assert.*;
+
+import java.io.IOException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Properties;
+import java.util.Set;
+
+import org.apache.nuvem.cloud.dataService.DataService;
+import org.apache.nuvem.cloud.dataService.DataServiceException;
+import org.apache.nuvem.cloud.dataService.DataServiceUtil;
+import org.apache.nuvem.cloud.dataService.Element;
+import org.apache.nuvem.cloud.dataService.Feature;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import com.amazonaws.services.simpledb.AmazonSimpleDBClient;
+import com.amazonaws.services.simpledb.model.BatchPutAttributesRequest;
+import com.amazonaws.services.simpledb.model.CreateDomainRequest;
+import com.amazonaws.services.simpledb.model.DeleteDomainRequest;
+import com.amazonaws.services.simpledb.model.Item;
+import com.amazonaws.services.simpledb.model.PutAttributesRequest;
+import com.amazonaws.services.simpledb.model.ReplaceableAttribute;
+import com.amazonaws.services.simpledb.model.ReplaceableItem;
+import com.amazonaws.services.simpledb.model.SelectRequest;
+
+/**
+ * 
+ * It's Required to have valid Amazon accessKey/secretKey pair in the
+ * test.properties file to run this test.
+ * 
+ */
+public class AmazonDataServiceImplTestCase {
+
+	private DataService dataService;
+
+	@Before
+	public void setUp() throws Exception {
+		dataService = new AmazonDataServiceImpl(getSDBClient());
+		clearData();
+	}
+
+	@After
+	public void tearDown() throws Exception {
+		dataService = null;
+
+	}
+
+	@Test
+	public void testCreateElement() throws DataServiceException {
+		Element e1 = new Element("student");
+		// For SDB it required set Id explicitly.
+		e1.setId("1");
+		e1.addFeature("name", "saman");
+		Feature f1 = new Feature("age", 12);
+		e1.addFeature(f1);
+		dataService.createElement(e1);
+
+		String selectExpression = "select * from "
+				+ AmazonDataServiceImpl.AMAZON_DEFAULT_DOMAIN_NAME
+				+ " where itemName() in('student(1)')";
+		AmazonSimpleDBClient client = getSDBClient();
+		List<Item> items = client.select(
+				new SelectRequest().withSelectExpression(selectExpression))
+				.getItems();
+		assertNotNull(items);
+		assertNotNull(items.get(0));
+		assertEquals("student(1)", items.get(0).getName());
+		assertEquals(2, items.get(0).getAttributes().size());
+	}
+
+	@Test
+	public void testUpdateElement() throws DataServiceException,
+			InterruptedException {
+
+		// create sample data
+		AmazonSimpleDBClient client = getSDBClient();
+		client.createDomain(new CreateDomainRequest()
+				.withDomainName(AmazonDataServiceImpl.AMAZON_DEFAULT_DOMAIN_NAME));
+		List<ReplaceableItem> items = new ArrayList<ReplaceableItem>();
+		List<ReplaceableAttribute> attributes = new ArrayList<ReplaceableAttribute>();
+		String key = DataServiceUtil.createKey("student", "1");
+		attributes.add(new ReplaceableAttribute("name", "saman", true));
+		attributes.add(new ReplaceableAttribute("age", "12", true));
+		PutAttributesRequest putAttributesRequest = new PutAttributesRequest(
+				AmazonDataServiceImpl.AMAZON_DEFAULT_DOMAIN_NAME, key,
+				attributes);
+		client.putAttributes(putAttributesRequest);
+
+		Thread.sleep(2000);
+
+		Element element = dataService.getElement("student", "1");
+		assertNotNull(element);
+		assertEquals(key, element.getKey());
+		assertNotNull(element.getFeatures());
+		assertNotNull(element.getFeatures().size());
+		assertEquals(2, element.getFeatures().size());
+
+		Set<Feature> features = element.getFeatures();
+		element.getFeatures().removeAll(features);
+
+		element.addFeature("name", "kamal");
+		element.addFeature("age", "24");
+		element.addFeature("country", "LK");
+		dataService.updateElement(element);
+
+		Thread.sleep(5000);
+
+		Element element2 = dataService.getElement("student", "1");
+		for (Feature f : element2.getFeatures()) {
+			System.out.println(f.getValue());
+		}
+		assertNotNull(element2);
+		assertEquals("student(1)", element2.getKey());
+		assertNotNull(element2.getFeatures());
+		assertNotNull(element2.getFeatures().size());
+
+	}
+
+	@Test
+	public void testGetElement() throws DataServiceException {
+
+		// create sample data
+		AmazonSimpleDBClient client = getSDBClient();
+		client.createDomain(new CreateDomainRequest()
+				.withDomainName(AmazonDataServiceImpl.AMAZON_DEFAULT_DOMAIN_NAME));
+		BatchPutAttributesRequest batchPutAttributesRequest = new BatchPutAttributesRequest();
+		batchPutAttributesRequest
+				.setDomainName(AmazonDataServiceImpl.AMAZON_DEFAULT_DOMAIN_NAME);
+		List<ReplaceableItem> items = new ArrayList<ReplaceableItem>();
+		List<ReplaceableAttribute> attributes = new ArrayList<ReplaceableAttribute>();
+		String key = DataServiceUtil.createKey("student", "1");
+		attributes.add(new ReplaceableAttribute("name", "saman", true));
+		attributes.add(new ReplaceableAttribute("age", "12", true));
+		ReplaceableItem item = new ReplaceableItem(key, attributes);
+		items.add(item);
+		batchPutAttributesRequest.setItems(items);
+		client.batchPutAttributes(batchPutAttributesRequest);
+
+		Element element = dataService.getElement("student", "1");
+		assertNotNull(element);
+		assertEquals("student(1)", element.getKey());
+		assertNotNull(element.getFeatures());
+		assertNotNull(element.getFeatures().size());
+
+	}
+
+	@Test
+	public void testDeleteElement() throws DataServiceException,
+			InterruptedException {
+		// create sample data
+		AmazonSimpleDBClient client = getSDBClient();
+		client.createDomain(new CreateDomainRequest()
+				.withDomainName(AmazonDataServiceImpl.AMAZON_DEFAULT_DOMAIN_NAME));
+		List<ReplaceableItem> items = new ArrayList<ReplaceableItem>();
+		List<ReplaceableAttribute> attributes = new ArrayList<ReplaceableAttribute>();
+		String key = DataServiceUtil.createKey("student", "1");
+		attributes.add(new ReplaceableAttribute("name", "saman", true));
+		attributes.add(new ReplaceableAttribute("age", "12", true));
+		PutAttributesRequest putAttributesRequest = new PutAttributesRequest(
+				AmazonDataServiceImpl.AMAZON_DEFAULT_DOMAIN_NAME, key,
+				attributes);
+		client.putAttributes(putAttributesRequest);
+
+		Element element = dataService.getElement("student", "1");
+		assertNotNull(element);
+		assertEquals(key, element.getKey());
+		assertNotNull(element.getFeatures());
+		assertNotNull(element.getFeatures().size());
+		assertEquals(2, element.getFeatures().size());
+		Thread.sleep(5000);
+		boolean result = dataService.deleteElement(element);
+		assertTrue(result);
+		Thread.sleep(5000);
+		Element element2 = dataService.getElement("student", "1");
+		assertNull(element2);
+
+	}
+
+	private void clearData() {
+		DeleteDomainRequest deleteDomainRequest = new DeleteDomainRequest();
+		deleteDomainRequest
+				.setDomainName(AmazonDataServiceImpl.AMAZON_DEFAULT_DOMAIN_NAME);
+		getSDBClient().deleteDomain(deleteDomainRequest);
+	}
+
+	private AmazonSimpleDBClient getSDBClient() {
+		Properties props = new Properties();
+		URL url = ClassLoader.getSystemResource("test.properties");
+		try {
+			props.load(url.openStream());
+			final String accessKey = props.getProperty("accessKey");
+			final String secretKey = props.getProperty("secretKey");
+			return (AmazonSimpleDBClient) AmazonDataServiceClientFactory
+					.getAmazonWebServiceClient(accessKey, secretKey);
+		} catch (IOException e) {
+			e.printStackTrace();
+		}
+		return null;
+
+	}
+
+}

Propchange: incubator/nuvem/trunk/nuvem-amazon/src/test/java/org/apache/nuvem/cloud/dataService/impl/AmazonDataServiceImplTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/nuvem/trunk/nuvem-amazon/src/test/java/org/apache/nuvem/cloud/dataService/impl/MockAmazonSimpleDBClient.java
URL: http://svn.apache.org/viewvc/incubator/nuvem/trunk/nuvem-amazon/src/test/java/org/apache/nuvem/cloud/dataService/impl/MockAmazonSimpleDBClient.java?rev=1161611&view=auto
==============================================================================
--- incubator/nuvem/trunk/nuvem-amazon/src/test/java/org/apache/nuvem/cloud/dataService/impl/MockAmazonSimpleDBClient.java (added)
+++ incubator/nuvem/trunk/nuvem-amazon/src/test/java/org/apache/nuvem/cloud/dataService/impl/MockAmazonSimpleDBClient.java Thu Aug 25 15:46:02 2011
@@ -0,0 +1,134 @@
+/*
+ * 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.nuvem.cloud.dataService.impl;
+
+import com.amazonaws.AmazonClientException;
+import com.amazonaws.AmazonServiceException;
+import com.amazonaws.AmazonWebServiceClient;
+import com.amazonaws.ClientConfiguration;
+import com.amazonaws.services.simpledb.AmazonSimpleDB;
+import com.amazonaws.services.simpledb.model.BatchDeleteAttributesRequest;
+import com.amazonaws.services.simpledb.model.BatchPutAttributesRequest;
+import com.amazonaws.services.simpledb.model.CreateDomainRequest;
+import com.amazonaws.services.simpledb.model.DeleteAttributesRequest;
+import com.amazonaws.services.simpledb.model.DeleteDomainRequest;
+import com.amazonaws.services.simpledb.model.DomainMetadataRequest;
+import com.amazonaws.services.simpledb.model.DomainMetadataResult;
+import com.amazonaws.services.simpledb.model.GetAttributesRequest;
+import com.amazonaws.services.simpledb.model.GetAttributesResult;
+import com.amazonaws.services.simpledb.model.ListDomainsRequest;
+import com.amazonaws.services.simpledb.model.ListDomainsResult;
+import com.amazonaws.services.simpledb.model.PutAttributesRequest;
+import com.amazonaws.services.simpledb.model.SelectRequest;
+import com.amazonaws.services.simpledb.model.SelectResult;
+
+public class MockAmazonSimpleDBClient extends AmazonWebServiceClient implements AmazonSimpleDB{
+
+	public MockAmazonSimpleDBClient(){
+		super(null);
+	}
+	
+	public MockAmazonSimpleDBClient(ClientConfiguration clientConfiguration) {
+		super(clientConfiguration);
+		// TODO Auto-generated constructor stub
+	}
+
+	@Override
+	public SelectResult select(SelectRequest selectRequest)
+			throws AmazonServiceException, AmazonClientException {
+		// TODO Auto-generated method stub
+		return null;
+	}
+
+	@Override
+	public void putAttributes(PutAttributesRequest putAttributesRequest)
+			throws AmazonServiceException, AmazonClientException {
+		// TODO Auto-generated method stub
+		
+	}
+
+	@Override
+	public void batchDeleteAttributes(
+			BatchDeleteAttributesRequest batchDeleteAttributesRequest)
+			throws AmazonServiceException, AmazonClientException {
+		// TODO Auto-generated method stub
+		
+	}
+
+	@Override
+	public void deleteDomain(DeleteDomainRequest deleteDomainRequest)
+			throws AmazonServiceException, AmazonClientException {
+		// TODO Auto-generated method stub
+		
+	}
+
+	@Override
+	public void createDomain(CreateDomainRequest createDomainRequest)
+			throws AmazonServiceException, AmazonClientException {
+		// TODO Auto-generated method stub
+		
+	}
+
+	@Override
+	public void deleteAttributes(DeleteAttributesRequest deleteAttributesRequest)
+			throws AmazonServiceException, AmazonClientException {
+		// TODO Auto-generated method stub
+		
+	}
+
+	@Override
+	public ListDomainsResult listDomains(ListDomainsRequest listDomainsRequest)
+			throws AmazonServiceException, AmazonClientException {
+		// TODO Auto-generated method stub
+		return null;
+	}
+
+	@Override
+	public GetAttributesResult getAttributes(
+			GetAttributesRequest getAttributesRequest)
+			throws AmazonServiceException, AmazonClientException {
+		// TODO Auto-generated method stub
+		return null;
+	}
+
+	@Override
+	public void batchPutAttributes(
+			BatchPutAttributesRequest batchPutAttributesRequest)
+			throws AmazonServiceException, AmazonClientException {
+		// TODO Auto-generated method stub
+		
+	}
+
+	@Override
+	public DomainMetadataResult domainMetadata(
+			DomainMetadataRequest domainMetadataRequest)
+			throws AmazonServiceException, AmazonClientException {
+		// TODO Auto-generated method stub
+		return null;
+	}
+
+	@Override
+	public ListDomainsResult listDomains() throws AmazonServiceException,
+			AmazonClientException {
+		// TODO Auto-generated method stub
+		return null;
+	}
+
+}

Propchange: incubator/nuvem/trunk/nuvem-amazon/src/test/java/org/apache/nuvem/cloud/dataService/impl/MockAmazonSimpleDBClient.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/nuvem/trunk/nuvem-amazon/src/test/resources/test.properties
URL: http://svn.apache.org/viewvc/incubator/nuvem/trunk/nuvem-amazon/src/test/resources/test.properties?rev=1161611&view=auto
==============================================================================
--- incubator/nuvem/trunk/nuvem-amazon/src/test/resources/test.properties (added)
+++ incubator/nuvem/trunk/nuvem-amazon/src/test/resources/test.properties Thu Aug 25 15:46:02 2011
@@ -0,0 +1,20 @@
+#
+# 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.
+#
+accessKey=accessKey
+secretKey=secretKey
\ No newline at end of file

Propchange: incubator/nuvem/trunk/nuvem-amazon/src/test/resources/test.properties
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/dataService/DataService.java
URL: http://svn.apache.org/viewvc/incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/dataService/DataService.java?rev=1161611&r1=1161610&r2=1161611&view=diff
==============================================================================
--- incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/dataService/DataService.java (original)
+++ incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/dataService/DataService.java Thu Aug 25 15:46:02 2011
@@ -22,7 +22,11 @@ package org.apache.nuvem.cloud.dataServi
 import org.oasisopen.sca.annotation.Remotable;
 
 /**
- * The Interface DataService.
+ * The Interface DataService defines services provide by Nuvem key-value
+ * data-store component also act as abreaction layer for cloud platform specific
+ * data services. Element is the basic persistent unit and may contains number
+ * of Features that associate with the Element. DataService interface facilitate
+ * to create, update , read and delete Elements.
  */
 @Remotable
 public interface DataService {

Added: incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/dataService/DataServiceUtil.java
URL: http://svn.apache.org/viewvc/incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/dataService/DataServiceUtil.java?rev=1161611&view=auto
==============================================================================
--- incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/dataService/DataServiceUtil.java (added)
+++ incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/dataService/DataServiceUtil.java Thu Aug 25 15:46:02 2011
@@ -0,0 +1,23 @@
+package org.apache.nuvem.cloud.dataService;
+
+public class DataServiceUtil {
+	
+	public static String createKey(String kind , String id) {		
+		return kind.concat("(").concat(id).concat(")");			
+	}
+	
+	public static String getKind(String key){
+		if(key != null){
+			return key.substring(0, key.indexOf("("));
+		}
+		return null;
+	}
+	
+	public static String getId(String key){
+		if(key != null){
+			return key.substring(key.indexOf("(")+1, key.indexOf(")"));
+		}
+		return null;
+	}
+
+}

Propchange: incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/dataService/DataServiceUtil.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/dataService/Element.java
URL: http://svn.apache.org/viewvc/incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/dataService/Element.java?rev=1161611&r1=1161610&r2=1161611&view=diff
==============================================================================
--- incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/dataService/Element.java (original)
+++ incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/dataService/Element.java Thu Aug 25 15:46:02 2011
@@ -177,6 +177,10 @@ public class Element {
 		getFeatures().remove(feature);
 	}
 	
+	public void removeFeatures(Set<Feature> features){
+		getFeatures().remove(features);
+	}
+	
 
 	/**
 	 * Gets the features.

Modified: incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/dataService/Feature.java
URL: http://svn.apache.org/viewvc/incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/dataService/Feature.java?rev=1161611&r1=1161610&r2=1161611&view=diff
==============================================================================
--- incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/dataService/Feature.java (original)
+++ incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/dataService/Feature.java Thu Aug 25 15:46:02 2011
@@ -83,6 +83,39 @@ public class Feature {
 	public void setValue(String value) {
 		this.value = value;
 	}
+
+	@Override
+	public int hashCode() {
+		final int prime = 31;
+		int result = 1;
+		result = prime * result + ((name == null) ? 0 : name.hashCode());
+		result = prime * result + ((value == null) ? 0 : value.hashCode());
+		return result;
+	}
+
+	@Override
+	public boolean equals(Object obj) {
+		if (this == obj)
+			return true;
+		if (obj == null)
+			return false;
+		if (getClass() != obj.getClass())
+			return false;
+		Feature other = (Feature) obj;
+		if (name == null) {
+			if (other.name != null)
+				return false;
+		} else if (!name.equals(other.name))
+			return false;
+		if (value == null) {
+			if (other.value != null)
+				return false;
+		} else if (!value.equals(other.value))
+			return false;
+		return true;
+	}
+	
+	
 	
 	
 

Modified: incubator/nuvem/trunk/nuvem-google/src/main/java/org/apache/nuvem/cloud/dataService/impl/GoogleDataServiceImpl.java
URL: http://svn.apache.org/viewvc/incubator/nuvem/trunk/nuvem-google/src/main/java/org/apache/nuvem/cloud/dataService/impl/GoogleDataServiceImpl.java?rev=1161611&r1=1161610&r2=1161611&view=diff
==============================================================================
--- incubator/nuvem/trunk/nuvem-google/src/main/java/org/apache/nuvem/cloud/dataService/impl/GoogleDataServiceImpl.java (original)
+++ incubator/nuvem/trunk/nuvem-google/src/main/java/org/apache/nuvem/cloud/dataService/impl/GoogleDataServiceImpl.java Thu Aug 25 15:46:02 2011
@@ -34,7 +34,9 @@ import com.google.appengine.api.datastor
 import com.google.appengine.api.datastore.KeyFactory;
 
 /**
- * The Class GoogleDataServiceImpl.
+ * The Class GoogleDataServiceImpl is implementation of Nuvem DataService
+ * interface based on Google key-value data-store service. Element and Feature
+ * objects are mapped into GAE Entry and Properties.
  */
 public class GoogleDataServiceImpl implements DataService {
 
@@ -82,8 +84,7 @@ public class GoogleDataServiceImpl imple
 		}
 		Key key = datastoreService.put(entity);
 		element.setId(String.valueOf(key.getId()));
-		element.setPersist();
-		System.out.println(key);
+		element.setPersist();		
 		return element;
 	}
 
@@ -102,8 +103,7 @@ public class GoogleDataServiceImpl imple
 			}				
 			Key keyRet = datastoreService.put(entity);
 			element.setId(String.valueOf(keyRet.getId()));
-			element.setPersist();
-			System.out.println(keyRet);
+			element.setPersist();			
 			return element;
 
 		} catch (Exception e) {

Copied: incubator/nuvem/trunk/nuvem-google/src/test/java/org/apache/nuvem/cloud/dataService/impl/GoogleDataServiceImplTestCase.java (from r1152431, incubator/nuvem/trunk/nuvem-google/src/test/java/org/apache/nuvem/cloud/dataService/impl/GoogleDataServiceImplTest.java)
URL: http://svn.apache.org/viewvc/incubator/nuvem/trunk/nuvem-google/src/test/java/org/apache/nuvem/cloud/dataService/impl/GoogleDataServiceImplTestCase.java?p2=incubator/nuvem/trunk/nuvem-google/src/test/java/org/apache/nuvem/cloud/dataService/impl/GoogleDataServiceImplTestCase.java&p1=incubator/nuvem/trunk/nuvem-google/src/test/java/org/apache/nuvem/cloud/dataService/impl/GoogleDataServiceImplTest.java&r1=1152431&r2=1161611&rev=1161611&view=diff
==============================================================================
--- incubator/nuvem/trunk/nuvem-google/src/test/java/org/apache/nuvem/cloud/dataService/impl/GoogleDataServiceImplTest.java (original)
+++ incubator/nuvem/trunk/nuvem-google/src/test/java/org/apache/nuvem/cloud/dataService/impl/GoogleDataServiceImplTestCase.java Thu Aug 25 15:46:02 2011
@@ -41,7 +41,7 @@ import com.google.appengine.tools.develo
 /**
  * The Class GoogleDataServiceImplTest.
  */
-public class GoogleDataServiceImplTest {
+public class GoogleDataServiceImplTestCase {
 	
 	/** The data service. */
 	private DataService dataService ;

Modified: incubator/nuvem/trunk/nuvem-standalone/pom.xml
URL: http://svn.apache.org/viewvc/incubator/nuvem/trunk/nuvem-standalone/pom.xml?rev=1161611&r1=1161610&r2=1161611&view=diff
==============================================================================
--- incubator/nuvem/trunk/nuvem-standalone/pom.xml (original)
+++ incubator/nuvem/trunk/nuvem-standalone/pom.xml Thu Aug 25 15:46:02 2011
@@ -1,18 +1,15 @@
 <?xml version="1.0" encoding="UTF-8"?>
-	<!--
-		* 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.
-	-->
+<!-- * 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. -->
 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
 	<modelVersion>4.0.0</modelVersion>
@@ -45,7 +42,7 @@
 			<version>${tuscany.version}</version>
 			<scope>test</scope>
 		</dependency>
-		
+
 		<dependency>
 			<groupId>org.apache.tuscany.sca</groupId>
 			<artifactId>tuscany-sca-api</artifactId>
@@ -91,11 +88,15 @@
 			<type>pom</type>
 			<version>1.0.0-SNAPSHOT</version>
 		</dependency>
-
+		<dependency>
+			<groupId>me.prettyprint</groupId>
+			<artifactId>hector-core</artifactId>
+			<version>0.8.0-2</version>
+		</dependency>		
 		<dependency>
 			<groupId>org.slf4j</groupId>
 			<artifactId>slf4j-api</artifactId>
-			<version>1.5.3</version>
+			<version>1.6.1</version>
 		</dependency>
 
 		<dependency>

Added: incubator/nuvem/trunk/nuvem-standalone/src/main/java/org/apache/nuvem/cloud/dataService/impl/CassandraDataServiceImpl.java
URL: http://svn.apache.org/viewvc/incubator/nuvem/trunk/nuvem-standalone/src/main/java/org/apache/nuvem/cloud/dataService/impl/CassandraDataServiceImpl.java?rev=1161611&view=auto
==============================================================================
--- incubator/nuvem/trunk/nuvem-standalone/src/main/java/org/apache/nuvem/cloud/dataService/impl/CassandraDataServiceImpl.java (added)
+++ incubator/nuvem/trunk/nuvem-standalone/src/main/java/org/apache/nuvem/cloud/dataService/impl/CassandraDataServiceImpl.java Thu Aug 25 15:46:02 2011
@@ -0,0 +1,168 @@
+/*
+ * 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.nuvem.cloud.dataService.impl;
+
+import me.prettyprint.cassandra.serializers.StringSerializer;
+import me.prettyprint.cassandra.service.CassandraHostConfigurator;
+import me.prettyprint.hector.api.Cluster;
+import me.prettyprint.hector.api.Keyspace;
+import me.prettyprint.hector.api.beans.ColumnSlice;
+import me.prettyprint.hector.api.beans.HColumn;
+import me.prettyprint.hector.api.ddl.ColumnFamilyDefinition;
+import me.prettyprint.hector.api.ddl.KeyspaceDefinition;
+import me.prettyprint.hector.api.factory.HFactory;
+import me.prettyprint.hector.api.mutation.Mutator;
+import me.prettyprint.hector.api.query.QueryResult;
+import me.prettyprint.hector.api.query.SliceQuery;
+
+import org.apache.nuvem.cloud.dataService.DataService;
+import org.apache.nuvem.cloud.dataService.DataServiceException;
+import org.apache.nuvem.cloud.dataService.Element;
+import org.apache.nuvem.cloud.dataService.Feature;
+
+public class CassandraDataServiceImpl implements DataService {
+
+	private final static String DEFAULT_CLUSTER_NAME = "NuvemCluster";
+	private final static String DEFAULT_KEYSPACE_NAME = "NuvemData";
+	private final static String DEFAULT_HOST = "localhost";
+	private final static String DEFAULT_PORT = "9160";
+
+	private Cluster cluster;
+	private Keyspace keyspace;
+	private String keyspaceName;
+	private StringSerializer stringSerializer;
+
+	public CassandraDataServiceImpl() {
+		this(DEFAULT_CLUSTER_NAME, DEFAULT_KEYSPACE_NAME, DEFAULT_HOST,
+				DEFAULT_PORT);
+	}
+
+	public CassandraDataServiceImpl(String host, String port) {
+		this(DEFAULT_CLUSTER_NAME, DEFAULT_KEYSPACE_NAME, host, port);
+	}
+
+	public CassandraDataServiceImpl(String clusterName, String keyspaceName,
+			String host, String port) {
+		cluster = HFactory.createCluster(clusterName,
+				new CassandraHostConfigurator(host + ":" + port));
+		// The key space where all the data shall be stored
+		keyspace = HFactory.createKeyspace(keyspaceName, cluster);
+		this.keyspaceName = keyspaceName;
+		stringSerializer = StringSerializer.get();
+	}
+
+	public CassandraDataServiceImpl(Cluster cluster, Keyspace keyspace,
+			String keyspaceName) {
+		this.cluster = cluster;
+		this.keyspace = keyspace;
+		this.keyspaceName = keyspaceName;
+		stringSerializer = StringSerializer.get();
+	}
+
+	@Override
+	public Element createElement(Element element) throws DataServiceException {
+		saveElement(element);
+		return element;
+	}
+
+	@Override
+	public Element updateElement(Element element) throws DataServiceException {
+		String type = element.getType();
+		String id = element.getKey();
+		Mutator<String> mutator = getMutator();
+		mutator.addDeletion(id, type);
+		mutator.execute();
+		saveElement(element);
+		return element;
+	}
+
+	@Override
+	public Element getElement(String kind, String id)
+			throws DataServiceException {
+		SliceQuery<String, String, String> q = HFactory.createSliceQuery(
+				keyspace, stringSerializer, stringSerializer, stringSerializer);
+		q.setKey(id).setColumnFamily(kind)
+				.setRange(null, null, false, Integer.MAX_VALUE);
+		QueryResult<ColumnSlice<String, String>> r = q.execute();
+		ColumnSlice<String, String> cs = r.get();
+		Element element = new Element(kind);
+		element.setKey(id);
+		element.setPersist();
+		for (HColumn hc : cs.getColumns()) {
+			element.addFeature(String.valueOf(hc.getName()), hc.getValue());
+		}
+		return element;
+	}
+
+	@Override
+	public boolean deleteElement(Element element) throws DataServiceException {
+		String type = element.getType();
+		String id = element.getKey();
+		Mutator<String> mutator = getMutator();
+		mutator.addDeletion(id, type);
+		mutator.execute();
+		return true;
+	}
+
+	private Mutator getMutator() {
+		Mutator<String> mutator = HFactory.createMutator(keyspace,
+				stringSerializer);
+		return mutator;
+
+	}
+
+	private void saveElement(Element element) throws DataServiceException {
+		String type = element.getType();
+		String id = element.getKey();
+		createColumnFamilyifnotExsists(type);
+
+		Mutator<String> mutator = getMutator();
+		for (Feature feature : element.getFeatures()) {
+			mutator.addInsertion(
+					id,
+					type,
+					HFactory.createStringColumn(feature.getName(),
+							String.valueOf(feature.getValue())));
+		}
+		mutator.execute();
+	}
+
+	private void createColumnFamilyifnotExsists(String ColumnFamilyName) {
+		KeyspaceDefinition kd = cluster.describeKeyspace(keyspaceName);
+		boolean create = true;
+		for (ColumnFamilyDefinition c : kd.getCfDefs()) {
+			if (ColumnFamilyName != null
+					&& c.getName().equals(ColumnFamilyName)) {
+				create = false;
+			}
+		}
+
+		if (!create) {
+			// CF already exist;
+			return;
+		}
+
+		// create new CF
+		ColumnFamilyDefinition cfDef = HFactory.createColumnFamilyDefinition(
+				keyspaceName, ColumnFamilyName);
+		cluster.addColumnFamily(cfDef, false);
+	}
+
+}

Propchange: incubator/nuvem/trunk/nuvem-standalone/src/main/java/org/apache/nuvem/cloud/dataService/impl/CassandraDataServiceImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/nuvem/trunk/nuvem-standalone/src/test/java/org/apache/nuvem/cloud/dataService/impl/CassandraDataServiceImplTestCase.java
URL: http://svn.apache.org/viewvc/incubator/nuvem/trunk/nuvem-standalone/src/test/java/org/apache/nuvem/cloud/dataService/impl/CassandraDataServiceImplTestCase.java?rev=1161611&view=auto
==============================================================================
--- incubator/nuvem/trunk/nuvem-standalone/src/test/java/org/apache/nuvem/cloud/dataService/impl/CassandraDataServiceImplTestCase.java (added)
+++ incubator/nuvem/trunk/nuvem-standalone/src/test/java/org/apache/nuvem/cloud/dataService/impl/CassandraDataServiceImplTestCase.java Thu Aug 25 15:46:02 2011
@@ -0,0 +1,219 @@
+/*
+ * 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.nuvem.cloud.dataService.impl;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import me.prettyprint.cassandra.serializers.StringSerializer;
+import me.prettyprint.cassandra.service.CassandraHostConfigurator;
+import me.prettyprint.hector.api.Cluster;
+import me.prettyprint.hector.api.Keyspace;
+import me.prettyprint.hector.api.beans.ColumnSlice;
+import me.prettyprint.hector.api.beans.HColumn;
+import me.prettyprint.hector.api.ddl.ColumnFamilyDefinition;
+import me.prettyprint.hector.api.factory.HFactory;
+import me.prettyprint.hector.api.mutation.Mutator;
+import me.prettyprint.hector.api.query.QueryResult;
+import me.prettyprint.hector.api.query.SliceQuery;
+
+import org.apache.commons.collections.map.HashedMap;
+import org.apache.nuvem.cloud.dataService.DataService;
+import org.apache.nuvem.cloud.dataService.DataServiceException;
+import org.apache.nuvem.cloud.dataService.Element;
+import org.apache.nuvem.cloud.dataService.Feature;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+public class CassandraDataServiceImplTestCase {
+
+	private DataService dataService;
+
+	@Before
+	public void setUp() throws Exception {
+		dataService = new CassandraDataServiceImpl("LogsCluster", "NuvemData",
+				"localhost", "9160");
+	}
+
+	@After
+	public void tearDown() throws Exception {
+		System.out.println();
+		getCluster().dropColumnFamily("NuvemData", "student");
+		dataService = null;
+	}
+
+	@Test
+	public void testCreateElement() throws DataServiceException {
+		Element e1 = new Element("student");
+		e1.setId("1");
+		e1.addFeature("name", "sampleName1");
+		Feature f1 = new Feature("age", 12);
+		e1.addFeature(f1);
+		dataService.createElement(e1);
+
+		QueryResult<ColumnSlice<String, String>> r = getSliceQuery()
+				.setKey("student(1)").setColumnFamily("student")
+				.setRange(null, null, false, Integer.MAX_VALUE).execute();
+		ColumnSlice<String, String> cs = r.get();
+		Map<String, Object> results = new HashMap<String, Object>();
+		for (HColumn hc : cs.getColumns()) {
+			results.put(String.valueOf(hc.getName()), hc.getValue());
+		}
+		assertEquals(2, results.size());
+		assertNotNull(results.get("name"));
+		assertEquals("sampleName1", results.get("name"));
+		assertNotNull(results.get("age"));
+		assertEquals(12, Integer.parseInt((String) results.get("age")));
+
+	}
+
+	@Test
+	public void testUpdateCreateElement() throws DataServiceException {
+		Element e1 = new Element("student");
+		e1.setId("2");
+		e1.addFeature("name", "sampleName1");
+		Feature f1 = new Feature("age", 12);
+		e1.addFeature(f1);
+		dataService.createElement(e1);
+
+		QueryResult<ColumnSlice<String, String>> r = getSliceQuery()
+				.setKey("student(2)").setColumnFamily("student")
+				.setRange(null, null, false, Integer.MAX_VALUE).execute();
+		ColumnSlice<String, String> cs = r.get();
+		Map<String, Object> results = new HashMap<String, Object>();
+		for (HColumn hc : cs.getColumns()) {
+			results.put(String.valueOf(hc.getName()), hc.getValue());
+		}
+		assertEquals(2, results.size());
+		assertNotNull(results.get("name"));
+		assertEquals("sampleName1", results.get("name"));
+		assertNotNull(results.get("age"));
+		assertEquals(12, Integer.parseInt((String) results.get("age")));
+		assertNull(results.get("country"));
+
+		e1.addFeature("country", "LK");
+		dataService.updateElement(e1);
+
+		r = getSliceQuery().setKey("student(2)").setColumnFamily("student")
+				.setRange(null, null, false, Integer.MAX_VALUE).execute();
+		cs = r.get();
+		results = new HashMap<String, Object>();
+		for (HColumn hc : cs.getColumns()) {
+			results.put(String.valueOf(hc.getName()), hc.getValue());
+		}
+
+		assertEquals(3, results.size());
+		assertNotNull(results.get("name"));
+		assertEquals("sampleName1", results.get("name"));
+		assertNotNull(results.get("age"));
+		assertEquals(12, Integer.parseInt((String) results.get("age")));
+		assertNotNull(results.get("country"));
+		assertEquals("LK", results.get("country"));
+
+	}
+
+	@Test
+	public void testGetElement() throws DataServiceException {
+
+		ColumnFamilyDefinition cfDef = HFactory.createColumnFamilyDefinition(
+				"NuvemData", "student");
+		getCluster().addColumnFamily(cfDef, false);
+		Mutator<String> mutator = HFactory.createMutator(getKeyspace(),
+				StringSerializer.get());
+		mutator.addInsertion("student(3)", "student",
+				HFactory.createStringColumn("name", "sampleName1"));
+		mutator.addInsertion("student(3)", "student",
+				HFactory.createStringColumn("age", "12"));
+		mutator.execute();
+
+		Element ele = dataService.getElement("student", "student(3)");
+
+		assertNotNull(ele);
+		assertEquals("student(3)", ele.getKey());
+		Map<String, Object> results = new HashMap<String, Object>();
+		for (Feature f : ele.getFeatures()) {
+			results.put(f.getName(), f.getValue());
+		}
+		assertEquals(2, results.size());
+		assertNotNull(results.get("name"));
+		assertEquals("sampleName1", results.get("name"));
+		assertNotNull(results.get("age"));
+		assertEquals(12, Integer.parseInt((String) results.get("age")));
+
+	}
+
+	@Test
+	public void testDeleteElement() throws DataServiceException {
+
+		ColumnFamilyDefinition cfDef = HFactory.createColumnFamilyDefinition(
+				"NuvemData", "student");
+		getCluster().addColumnFamily(cfDef, false);
+		Mutator<String> mutator = HFactory.createMutator(getKeyspace(),
+				StringSerializer.get());
+		mutator.addInsertion("student(4)", "student",
+				HFactory.createStringColumn("name", "sampleName1"));
+		mutator.addInsertion("student(4)", "student",
+				HFactory.createStringColumn("age", "12"));
+		mutator.execute();
+
+		Element e1 = new Element("student");
+		e1.setId("4");
+		boolean re = dataService.deleteElement(e1);
+
+		assertTrue(re);
+
+		QueryResult<ColumnSlice<String, String>> r = getSliceQuery()
+				.setKey("student(4)").setColumnFamily("student")
+				.setRange(null, null, false, Integer.MAX_VALUE).execute();
+		ColumnSlice<String, String> cs = r.get();
+		Map<String, Object> results = new HashMap<String, Object>();
+		for (HColumn hc : cs.getColumns()) {
+			results.put(String.valueOf(hc.getName()), hc.getValue());
+		}
+		assertEquals(0, results.size());
+
+	}
+
+	private SliceQuery getSliceQuery() {
+		// The key space where all the data shall be stored
+		SliceQuery<String, String, String> q = HFactory.createSliceQuery(
+				getKeyspace(), StringSerializer.get(), StringSerializer.get(),
+				StringSerializer.get());
+		return q;
+	}
+
+	private Keyspace getKeyspace() {
+		return HFactory.createKeyspace("NuvemData", getCluster());
+	}
+
+	private Cluster getCluster() {
+		Cluster cluster = HFactory.createCluster("LogsCluster",
+				new CassandraHostConfigurator("localhost:9160"));
+		return cluster;
+
+	}
+
+}

Propchange: incubator/nuvem/trunk/nuvem-standalone/src/test/java/org/apache/nuvem/cloud/dataService/impl/CassandraDataServiceImplTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/nuvem/trunk/pom.xml
URL: http://svn.apache.org/viewvc/incubator/nuvem/trunk/pom.xml?rev=1161611&r1=1161610&r2=1161611&view=diff
==============================================================================
--- incubator/nuvem/trunk/pom.xml (original)
+++ incubator/nuvem/trunk/pom.xml Thu Aug 25 15:46:02 2011
@@ -197,6 +197,7 @@
                 <module>nuvem-parallel</module>
                 <module>nuvem-ibm</module>
 		    	<module>nuvem-azure</module>
+                <module>nuvem-amazon</module>
             </modules>
         </profile>
 



Mime
View raw message