Skip to content

Commit

Permalink
Merge pull request #50 from rpmoore/master
Browse files Browse the repository at this point in the history
Updated names of directories so maven layout makes more sense
  • Loading branch information
hansdude committed Oct 30, 2014
2 parents 5fab2f2 + 9818bcf commit d651d33
Show file tree
Hide file tree
Showing 174 changed files with 128 additions and 73 deletions.
48 changes: 47 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,57 @@ ds3_java_sdk

To install the latest ds3_java_sdk either download the latest release jar file from the [Releases](../../releases) page or clone the repository with `git clone https://github.com/SpectraLogic/ds3_java_sdk.git`, cd to `ds3_java_sdk` and run `./gradlew clean sdk:install` to install the sdk into your local maven repository.

The SDK can also be included directly into a Maven or Gradle build. To include the SDK into maven add the following to the `pom.xml` file:

```xml

<project>
...
<repositories>
<repository>
<id>Spectra-Github</id>
<url>https://spectralogic.github.io/java/repository</url>
</repository>
</repositories>
...
<dependencies>
...
<dependency>
<groupId>com.spectralogic.ds3</groupId>
<artifactId>ds3-sdk</artifactId>
<version>0.7.6-SNAPSHOT</version>
</dependency>
...
</dependencies>
</project>

```

To include the sdk into Gradle include the following in the `build.gradle` file:

```groovy
repositories {
...
maven {
url 'https://spectralogic.github.io/java/repository'
}
...
}
dependencies {
...
compile 'com.spectralogic.ds3:ds3-sdk:0.7.6-SNAPSHOT'
...
}
```

## Tests

In addition to unit tests in the main `sdk` module, there are additional integration tests in the `integration` module. Please see the integration [README](integration/README.md) for details on running the tests. To just run the SDK's unit tests use:

./gradlew clean sdk:test
./gradlew clean ds3-sdk:test

## Javadoc

Expand Down
14 changes: 10 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
*/

allprojects {
group = 'com.spectralogic'
version = '0.7.5-SNAPSHOT'
group = 'com.spectralogic.ds3'
version = '0.7.6-SNAPSHOT'
}

subprojects {
Expand All @@ -38,8 +38,14 @@ task wrapper(type: Wrapper) {
gradleVersion = '2.1'
}

project(':integration') {
project(':ds3-sdk-integration') {
dependencies {
compile project(':sdk')
compile project(':ds3-sdk')
}
}

project(':ds3-sdk-samples') {
dependencies {
compile project(':ds3-sdk')
}
}
File renamed without changes.
File renamed without changes.
Empty file added ds3-sdk-samples/build.gradle
Empty file.
2 changes: 0 additions & 2 deletions sdk/build.gradle → ds3-sdk/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
install.dependsOn test //make sure that the tests get ran before attempting to install

jar.baseName = 'ds3_java_sdk'

dependencies {
compile 'org.apache.httpcomponents:httpclient:4.3.2'
compile 'commons-codec:commons-codec:1.8'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package com.spectralogic.ds3client;

import com.spectralogic.ds3client.models.Credentials;
import com.spectralogic.ds3client.models.bulk.Node;
import com.spectralogic.ds3client.networking.ConnectionDetails;

import java.net.URI;
Expand Down Expand Up @@ -68,6 +69,17 @@ public ConnectionDetailsImpl build() {

}

public static ConnectionDetails newForNode(final Node node, final ConnectionDetails connectionDetails) {
final Builder connectionBuilder = builder(node.getEndpoint(), connectionDetails.getCredentials())
.withRedirectRetries(connectionDetails.getRetries())
.withHttps(connectionDetails.isHttps())
.withCertificateVerification(connectionDetails.isCertificateVerification())
.withBufferSize(connectionDetails.getBufferSize())
.withProxy(connectionDetails.getProxy());

return connectionBuilder.build();
}

private final String endpoint;
private final Credentials credentials;
private final boolean https;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import com.spectralogic.ds3client.commands.*;
import com.spectralogic.ds3client.models.bulk.Node;
import com.spectralogic.ds3client.networking.ConnectionDetails;

import java.io.IOException;
import java.security.SignatureException;
Expand Down Expand Up @@ -44,6 +45,8 @@
*/
public interface Ds3Client {

public abstract ConnectionDetails getConnectionDetails();

/**
* Gets the list of buckets.
* @param request The Service Request object used to customize the HTTP request, {@link com.spectralogic.ds3client.commands.GetServiceRequest}
Expand Down Expand Up @@ -239,7 +242,7 @@ public abstract ModifyJobResponse modifyJob(ModifyJobRequest request)
throws IOException, SignatureException;

/**
* Creates a factory based on a set of nodes that can return clients by node id.
* Creates a new Ds3Client instance for the system pointed to by Node.
*/
public abstract Ds3ClientFactory buildFactory(Iterable<Node> nodes);
public abstract Ds3Client newForNode(Node node);
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
package com.spectralogic.ds3client;

import com.spectralogic.ds3client.models.Credentials;
import com.spectralogic.ds3client.models.bulk.Node;
import com.spectralogic.ds3client.networking.ConnectionDetails;
import com.spectralogic.ds3client.networking.NetworkClient;
import com.spectralogic.ds3client.utils.Builder;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import com.spectralogic.ds3client.commands.*;
import com.spectralogic.ds3client.models.bulk.Node;
import com.spectralogic.ds3client.networking.ConnectionDetails;
import com.spectralogic.ds3client.networking.NetworkClient;

import java.io.IOException;
Expand All @@ -34,6 +35,11 @@ NetworkClient getNetClient() {
return this.netClient;
}

@Override
public ConnectionDetails getConnectionDetails() {
return this.netClient.getConnectionDetails();
}

@Override
public GetServiceResponse getService(final GetServiceRequest request) throws IOException, SignatureException {
return new GetServiceResponse(this.netClient.getResponse(request));
Expand Down Expand Up @@ -119,13 +125,10 @@ public ModifyJobResponse modifyJob(final ModifyJobRequest request) throws IOExce
}

@Override
public Ds3ClientFactory buildFactory(final Iterable<Node> nodes) {
return new Ds3ClientFactory() {
@Override
public Ds3Client getClientForNodeId(final UUID nodeId) {
//TODO: pay attention to actual nodes.
return Ds3ClientImpl.this;
}
};
public Ds3Client newForNode(final Node node) {
final ConnectionDetails newConnectionDetails = ConnectionDetailsImpl.newForNode(node, this.getConnectionDetails());
final NetworkClient netClient = new NetworkClientImpl(newConnectionDetails);

return new Ds3ClientImpl(netClient);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,15 @@
import com.google.common.util.concurrent.ListeningExecutorService;
import com.google.common.util.concurrent.MoreExecutors;
import com.spectralogic.ds3client.Ds3Client;
import com.spectralogic.ds3client.Ds3ClientFactory;
import com.spectralogic.ds3client.Ds3ClientBuilder;
import com.spectralogic.ds3client.models.bulk.BulkObject;
import com.spectralogic.ds3client.models.bulk.Node;
import com.spectralogic.ds3client.models.bulk.Objects;
import com.spectralogic.ds3client.serializer.XmlProcessingException;

import java.io.IOException;
import java.security.SignatureException;
import java.util.ArrayList;
import java.util.List;
import java.util.*;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Executors;
Expand Down Expand Up @@ -59,12 +58,12 @@ public void transferChunks(
final Iterable<Node> nodes,
final Iterable<Objects> chunks)
throws SignatureException, IOException, XmlProcessingException {
final Map<UUID, Node> nodeMap = buildNodeMap(nodes);
final ListeningExecutorService executor = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(maxParallelRequests));
try {
final List<ListenableFuture<?>> tasks = new ArrayList<>();
final Ds3ClientFactory clientFactory = this.mainClient.buildFactory(nodes);
for (final Objects chunk : chunks) {
final Ds3Client client = clientFactory.getClientForNodeId(chunk.getNodeId());
final Ds3Client client = mainClient.newForNode(nodeMap.get(chunk.getNodeId()));
for (final BulkObject ds3Object : chunk) {
final ObjectPart part = new ObjectPart(ds3Object.getOffset(), ds3Object.getLength());
if (this.partTracker.containsPart(ds3Object.getName(), part)) {
Expand All @@ -85,6 +84,14 @@ public Object call() throws Exception {
}
}

private static Map<UUID, Node> buildNodeMap(final Iterable<Node> nodes) {
final Map<UUID, Node> nodeMap = new HashMap<>();
for(final Node node: nodes) {
nodeMap.put(node.getId(), node);
}
return nodeMap;
}

private static void executeWithExceptionHandling(final List<ListenableFuture<?>> tasks)
throws IOException, SignatureException, XmlProcessingException {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@
package com.spectralogic.ds3client;

import com.spectralogic.ds3client.commands.*;
import com.spectralogic.ds3client.models.Bucket;
import com.spectralogic.ds3client.models.Contents;
import com.spectralogic.ds3client.models.ListAllMyBucketsResult;
import com.spectralogic.ds3client.models.ListBucketResult;
import com.spectralogic.ds3client.models.*;
import com.spectralogic.ds3client.models.bulk.*;
import com.spectralogic.ds3client.models.bulk.Objects;
import com.spectralogic.ds3client.networking.FailedRequestException;
Expand Down Expand Up @@ -616,4 +613,17 @@ public void modifyJob() throws SignatureException, IOException {
.getMasterObjectList()
);
}

@Test
public void newForNode() {
final Ds3Client client = Ds3ClientBuilder.create("endpoint", new Credentials("access", "key")).build();

final Node node = new Node();
node.setEndpoint("newEndpoint");

final Ds3Client newClient = client.newForNode(node);
assertThat(newClient.getConnectionDetails().getEndpoint(), is("newEndpoint"));
assertThat(newClient.getConnectionDetails().getCredentials().getClientId(), is("access"));
assertThat(newClient.getConnectionDetails().getCredentials().getKey(), is("key"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import com.google.common.base.Stopwatch;
import com.google.common.collect.Lists;
import com.spectralogic.ds3client.Ds3Client;
import com.spectralogic.ds3client.Ds3ClientFactory;
import com.spectralogic.ds3client.commands.*;
import com.spectralogic.ds3client.helpers.Ds3ClientHelpers.Job;
import com.spectralogic.ds3client.helpers.Ds3ClientHelpers.ObjectChannelBuilder;
Expand All @@ -44,6 +43,7 @@
import static com.spectralogic.ds3client.helpers.ResponseBuilders.*;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import static org.mockito.Mockito.mock;

public class Ds3ClientHelpers_Test {
private static final String MYBUCKET = "mybucket";
Expand All @@ -52,6 +52,7 @@ public class Ds3ClientHelpers_Test {
public void testReadObjects() throws SignatureException, IOException, XmlProcessingException {
final Ds3Client ds3Client = buildDs3ClientForBulk();


final BulkGetResponse buildBulkGetResponse = buildBulkGetResponse();
Mockito.when(ds3Client.bulkGet(hasChunkOrdering(ChunkClientProcessingOrderGuarantee.NONE))).thenReturn(buildBulkGetResponse);

Expand Down Expand Up @@ -91,10 +92,9 @@ public SeekableByteChannel buildChannel(final String key) throws IOException {

@Test(expected = StubException.class)
public void testReadObjectsWithFailedGet() throws SignatureException, IOException, XmlProcessingException {
final Ds3Client ds3Client = Mockito.mock(Ds3Client.class);
final Ds3Client ds3Client = mock(Ds3Client.class);

final Ds3ClientFactory ds3ClientFactory = ds3ClientFactory(ds3Client);
Mockito.when(ds3Client.buildFactory(Mockito.<Iterable<Node>>any())).thenReturn(ds3ClientFactory);
Mockito.when(ds3Client.newForNode(Mockito.<Node>any())).thenReturn(ds3Client);

final BulkGetResponse buildBulkGetResponse = buildBulkGetResponse();
Mockito.when(ds3Client.bulkGet(hasChunkOrdering(ChunkClientProcessingOrderGuarantee.NONE))).thenReturn(buildBulkGetResponse);
Expand Down Expand Up @@ -136,7 +136,7 @@ public void testWriteObjects() throws SignatureException, IOException, XmlProces
Mockito.when(ds3Client.allocateJobChunk(hasChunkId(CHUNK_ID_2)))
.thenReturn(allocateResponse3);

final PutObjectResponse response = Mockito.mock(PutObjectResponse.class);
final PutObjectResponse response = mock(PutObjectResponse.class);
Mockito.when(ds3Client.putObject(putRequestHas(MYBUCKET, "foo", jobId, 0, "foo co"))).thenReturn(response);
Mockito.when(ds3Client.putObject(putRequestHas(MYBUCKET, "bar", jobId, 0, "bar contents"))).thenReturn(response);
Mockito.when(ds3Client.putObject(putRequestHas(MYBUCKET, "baz", jobId, 0, "baz co"))).thenReturn(response);
Expand Down Expand Up @@ -169,18 +169,17 @@ public SeekableByteChannel buildChannel(final String key) throws IOException {

@Test
public void testWriteObjectsWithFailedPut() throws SignatureException, IOException, XmlProcessingException {
final Ds3Client ds3Client = Mockito.mock(Ds3Client.class);
final Ds3Client ds3Client = mock(Ds3Client.class);

final Ds3ClientFactory ds3ClientFactory = ds3ClientFactory(ds3Client);
Mockito.when(ds3Client.buildFactory(Mockito.<Iterable<Node>>any())).thenReturn(ds3ClientFactory);
Mockito.when(ds3Client.newForNode(Mockito.<Node>any())).thenReturn(ds3Client);

final BulkPutResponse buildBulkPutResponse = buildBulkPutResponse();
Mockito.when(ds3Client.bulkPut(Mockito.any(BulkPutRequest.class))).thenReturn(buildBulkPutResponse);

final AllocateJobChunkResponse allocateResponse = buildAllocateResponse2();
Mockito.when(ds3Client.allocateJobChunk(hasChunkId(CHUNK_ID_1))).thenReturn(allocateResponse);

final PutObjectResponse putResponse = Mockito.mock(PutObjectResponse.class);
final PutObjectResponse putResponse = mock(PutObjectResponse.class);
Mockito.when(ds3Client.putObject(putRequestHas(MYBUCKET, "foo", jobId, 0, "foo co"))).thenThrow(new StubException());
Mockito.when(ds3Client.putObject(putRequestHas(MYBUCKET, "baz", jobId, 0, "baz co"))).thenReturn(putResponse);

Expand Down Expand Up @@ -213,7 +212,7 @@ private static final class StubException extends RuntimeException {

@Test
public void testListObjects() throws SignatureException, IOException, XmlProcessingException {
final Ds3Client ds3Client = Mockito.mock(Ds3Client.class);
final Ds3Client ds3Client = mock(Ds3Client.class);
Mockito.when(ds3Client.getBucket(getBucketHas(MYBUCKET, null))).thenReturn(new StubGetBucketResponse(0));
Mockito.when(ds3Client.getBucket(getBucketHas(MYBUCKET, "baz"))).thenReturn(new StubGetBucketResponse(1));

Expand Down Expand Up @@ -317,10 +316,7 @@ private static Contents buildContents(

private static Ds3Client buildDs3ClientForBulk() throws IOException,
SignatureException {
final Ds3Client ds3Client = Mockito.mock(Ds3Client.class);

final Ds3ClientFactory ds3ClientFactory = ds3ClientFactory(ds3Client);
Mockito.when(ds3Client.buildFactory(Mockito.<Iterable<Node>>any())).thenReturn(ds3ClientFactory);
final Ds3Client ds3Client = mock(Ds3Client.class);

final GetAvailableJobChunksResponse jobChunksResponse1 = buildJobChunksResponse1();
final GetAvailableJobChunksResponse jobChunksResponse2 = buildJobChunksResponse2();
Expand All @@ -330,6 +326,8 @@ private static Ds3Client buildDs3ClientForBulk() throws IOException,
.thenReturn(jobChunksResponse2)
.thenReturn(jobChunksResponse3);

Mockito.when(ds3Client.newForNode(Mockito.<Node>any())).thenReturn(ds3Client);

return ds3Client;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,10 @@

package com.spectralogic.ds3client.helpers;

import com.spectralogic.ds3client.Ds3Client;
import com.spectralogic.ds3client.Ds3ClientFactory;
import com.spectralogic.ds3client.commands.*;
import com.spectralogic.ds3client.models.bulk.*;
import com.spectralogic.ds3client.utils.ByteArraySeekableByteChannel;

import org.mockito.Mockito;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;

Expand Down Expand Up @@ -163,12 +160,6 @@ public GetObjectResponse answer(final InvocationOnMock invocation) throws Throwa
};
}

public static Ds3ClientFactory ds3ClientFactory(final Ds3Client client) {
final Ds3ClientFactory factory = mock(Ds3ClientFactory.class);
when(factory.getClientForNodeId(Mockito.<UUID>any())).thenReturn(client);
return factory;
}

public static SeekableByteChannel channelWithContents(final String contents) {
return writeToChannel(contents, new ByteArraySeekableByteChannel());
}
Expand Down
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit d651d33

Please sign in to comment.