adding a simpledb demo

This commit is contained in:
Luis A. Bastiao Silva 2010-12-20 22:49:54 +00:00
parent cb880cfcf0
commit 4e46527511
3 changed files with 184 additions and 0 deletions

View File

@ -0,0 +1,29 @@
====
Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
====================================================================
Licensed 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.
====================================================================
====
#
# this is a simple example command line client to test usage of simpledb
# functions like putAttribute is tested and then it select and retrieve results.
# 1. execute 'mvn install' to build the sample
# 2. invoke the jar, passing your aws credentials and the bucket you wish to create
# ex.
# java -jar target/jclouds-aws-demo-simpledb-jar-with-dependencies.jar $AWS_USER $AWS_PWD simpledbtest
# Further information: Luís A. astião Silva bastiao@ua.pt>

View File

@ -0,0 +1,75 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
====================================================================
Licensed 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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.jclouds</groupId>
<artifactId>jclouds-aws-demos-project</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>jclouds-aws-demo-simpledb</artifactId>
<name>jclouds simpledb sample that putAttributes and select it</name>
<description>jclouds simpledb sample that putAttributes and select it</description>
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>org.jclouds.aws.s3.samples.MainApp</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>org.jclouds.aws.simpledb.samples.MainApp</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,80 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed 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.jclouds.aws.simpledb.samples;
import java.io.IOException;
import java.util.Map;
import java.util.Properties;
import org.jclouds.aws.domain.Region;
import org.jclouds.aws.simpledb.SimpleDBAsyncClient;
import org.jclouds.aws.simpledb.SimpleDBClient;
import org.jclouds.aws.simpledb.domain.AttributePair;
import org.jclouds.aws.simpledb.domain.Item;
import org.jclouds.aws.simpledb.options.ListDomainsOptions;
import org.jclouds.rest.RestContext;
import org.jclouds.rest.RestContextFactory;
import com.google.common.collect.LinkedHashMultimap;
import com.google.common.collect.Multimap;
/**
* This the Main class of an Application that demonstrates the use of the simpledb.
*
* Usage is: java MainApp \"accesskeyid\" \"secretkey\"
*
* @author Luís A. Bastião Silva <bastiao@ua.pt>
*
*/
public class MainApp
{
public static int PARAMETERS = 3;
public static String INVALID_SYNTAX = "Invalid number of parameters. Syntax is: \"accesskeyid\" \"secretkey\" \"bucketName\" ";
public static void main(String[] args) throws IOException {
// Args
String accesskeyid = args[0];
String secretkey = args[1];
Properties properties = new Properties();
properties.setProperty("simpledb.identity", accesskeyid);
properties.setProperty("simpledb.credential", secretkey);
RestContext<SimpleDBClient, SimpleDBAsyncClient> context = new RestContextFactory().createContext("simpledb", "AKIAJODKICBEKG7MM4XA", "FfqiNSiC88B6tJPDIOKUWUJGY68BQaQpkNz6Fsgq", new Properties());
AttributePair p = new AttributePair("AccessNumber", "1213123", true);
Multimap<String,AttributePair> m =LinkedHashMultimap.create();
m.put("AccessNumber", p);
Item attributes = new Item(m);
// Use Provider API
context.getApi().putAttributes(Region.EU_WEST_1, "tse", "AccessNumber", attributes );
//context.getApi().createDomainInRegion(Region.EU_WEST_1, "tse");
Map<String, Item> results = context.getApi().select(Region.EU_WEST_1, "select * from tse");
System.out.println(results);
ListDomainsOptions [] list = new ListDomainsOptions[100];
//context.getApi().listDomainsInRegion(Region.EU_WEST_1, list);
System.out.println(list[0]);
context.close();
}
}