mirror of https://github.com/apache/jclouds.git
JCLOUDS-505: Remove unused ObjectMD5
The only users of this seem to be org.jclouds.atmos.blobstore.strategy.FindMD5InUserMetadata and org.jclouds.azureblob.blobstore.strategy.FindMD5InBlobProperties which are themselves unused.
This commit is contained in:
parent
3f22f6738d
commit
a45124c51a
|
@ -24,12 +24,10 @@ import org.jclouds.atmos.AtmosClient;
|
|||
import org.jclouds.atmos.blobstore.AtmosAsyncBlobStore;
|
||||
import org.jclouds.atmos.blobstore.AtmosBlobRequestSigner;
|
||||
import org.jclouds.atmos.blobstore.AtmosBlobStore;
|
||||
import org.jclouds.atmos.blobstore.strategy.FindMD5InUserMetadata;
|
||||
import org.jclouds.blobstore.AsyncBlobStore;
|
||||
import org.jclouds.blobstore.BlobRequestSigner;
|
||||
import org.jclouds.blobstore.BlobStore;
|
||||
import org.jclouds.blobstore.attr.ConsistencyModel;
|
||||
import org.jclouds.blobstore.strategy.ContainsValueInListStrategy;
|
||||
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
import com.google.common.cache.CacheLoader;
|
||||
|
@ -50,7 +48,6 @@ public class AtmosBlobStoreContextModule extends AbstractModule {
|
|||
bind(ConsistencyModel.class).toInstance(ConsistencyModel.EVENTUAL);
|
||||
bind(AsyncBlobStore.class).to(AtmosAsyncBlobStore.class).in(Scopes.SINGLETON);
|
||||
bind(BlobStore.class).to(AtmosBlobStore.class).in(Scopes.SINGLETON);
|
||||
bind(ContainsValueInListStrategy.class).to(FindMD5InUserMetadata.class);
|
||||
bind(BlobRequestSigner.class).to(AtmosBlobRequestSigner.class);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,130 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jclouds.atmos.blobstore.strategy;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static com.google.common.base.Throwables.propagate;
|
||||
import static org.jclouds.concurrent.FutureIterables.awaitCompletion;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.SynchronousQueue;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.inject.Named;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.Constants;
|
||||
import org.jclouds.atmos.AtmosAsyncClient;
|
||||
import org.jclouds.atmos.domain.AtmosObject;
|
||||
import org.jclouds.blobstore.domain.BlobMetadata;
|
||||
import org.jclouds.blobstore.functions.ObjectMD5;
|
||||
import org.jclouds.blobstore.internal.BlobRuntimeException;
|
||||
import org.jclouds.blobstore.options.ListContainerOptions;
|
||||
import org.jclouds.blobstore.strategy.ContainsValueInListStrategy;
|
||||
import org.jclouds.blobstore.strategy.ListBlobsInContainer;
|
||||
import org.jclouds.logging.Logger;
|
||||
|
||||
import com.google.common.base.Throwables;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
import com.google.common.util.concurrent.ListeningExecutorService;
|
||||
import com.google.inject.Inject;
|
||||
|
||||
/**
|
||||
* Searches Content-MD5 tag for the value associated with the value
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Singleton
|
||||
public class FindMD5InUserMetadata implements ContainsValueInListStrategy {
|
||||
@Resource
|
||||
protected Logger logger = Logger.NULL;
|
||||
protected final ObjectMD5 objectMD5;
|
||||
protected final ListBlobsInContainer getAllBlobMetadata;
|
||||
private final AtmosAsyncClient client;
|
||||
private final ListeningExecutorService userExecutor;
|
||||
/**
|
||||
* maximum duration of an blob Request
|
||||
*/
|
||||
@Inject(optional = true)
|
||||
@Named(Constants.PROPERTY_REQUEST_TIMEOUT)
|
||||
protected Long maxTime;
|
||||
|
||||
@Inject
|
||||
FindMD5InUserMetadata(@Named(Constants.PROPERTY_USER_THREADS) ListeningExecutorService userExecutor, ObjectMD5 objectMD5,
|
||||
ListBlobsInContainer getAllBlobMetadata, AtmosAsyncClient client) {
|
||||
this.objectMD5 = objectMD5;
|
||||
this.getAllBlobMetadata = getAllBlobMetadata;
|
||||
this.client = client;
|
||||
this.userExecutor = userExecutor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final String containerName, Object value, ListContainerOptions options) {
|
||||
final byte[] toSearch = objectMD5.apply(value);
|
||||
final BlockingQueue<Boolean> queue = new SynchronousQueue<Boolean>();
|
||||
Map<String, ListenableFuture<?>> responses = Maps.newHashMap();
|
||||
for (BlobMetadata md : getAllBlobMetadata.execute(containerName, options)) {
|
||||
final ListenableFuture<AtmosObject> future = client.headFile(containerName + "/" + md.getName());
|
||||
future.addListener(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
AtmosObject object = future.get();
|
||||
checkNotNull(object.getSystemMetadata(), object + " has no content metadata");
|
||||
if (object.getSystemMetadata().getContentMD5() != null) {
|
||||
if (Arrays.equals(toSearch, object.getSystemMetadata().getContentMD5())) {
|
||||
queue.put(true);
|
||||
}
|
||||
} else {
|
||||
logger.debug("object %s has no content md5", object.getSystemMetadata().getObjectID());
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
Throwables.propagate(e);
|
||||
} catch (ExecutionException e) {
|
||||
Throwables.propagate(e);
|
||||
}
|
||||
}
|
||||
}, userExecutor);
|
||||
responses.put(md.getName(), future);
|
||||
}
|
||||
Map<String, Exception> exceptions;
|
||||
try {
|
||||
exceptions = awaitCompletion(responses, userExecutor, maxTime, logger,
|
||||
String.format("searching for md5 in container %s", containerName));
|
||||
} catch (TimeoutException te) {
|
||||
throw propagate(te);
|
||||
}
|
||||
if (exceptions.size() > 0)
|
||||
throw new BlobRuntimeException(String.format("searching for md5 in container %s: %s", containerName,
|
||||
exceptions));
|
||||
try {
|
||||
return queue.poll(1, TimeUnit.MICROSECONDS) != null;
|
||||
} catch (InterruptedException e) {
|
||||
Throwables.propagate(e);
|
||||
return false;
|
||||
} catch (Exception e) {
|
||||
Throwables.propagateIfPossible(e, BlobRuntimeException.class);
|
||||
throw new BlobRuntimeException(String.format("Error searching for ETAG of value: [%s] in container:%s", value,
|
||||
containerName), e);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,62 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jclouds.atmos.blobstore.config;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import org.jclouds.ContextBuilder;
|
||||
import org.jclouds.atmos.AtmosApiMetadata;
|
||||
import org.jclouds.atmos.blobstore.strategy.FindMD5InUserMetadata;
|
||||
import org.jclouds.blobstore.BlobStoreContext;
|
||||
import org.jclouds.blobstore.internal.BlobStoreContextImpl;
|
||||
import org.jclouds.blobstore.strategy.ContainsValueInListStrategy;
|
||||
import org.jclouds.logging.config.NullLoggingModule;
|
||||
import org.jclouds.rest.internal.BaseRestApiTest.MockModule;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.Module;
|
||||
|
||||
/**
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Test(groups = "unit")
|
||||
public class AtmosBlobStoreModuleTest {
|
||||
|
||||
Injector createInjector() {
|
||||
return ContextBuilder
|
||||
.newBuilder(new AtmosApiMetadata())
|
||||
.credentials("uid", "key")
|
||||
.modules(
|
||||
ImmutableSet.<Module> of(new MockModule(),new NullLoggingModule()))
|
||||
.buildInjector();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testContextImpl() {
|
||||
|
||||
Injector injector = createInjector();
|
||||
BlobStoreContext handler = injector.getInstance(BlobStoreContext.class);
|
||||
assertEquals(handler.getClass(), BlobStoreContextImpl.class);
|
||||
ContainsValueInListStrategy valueList = injector
|
||||
.getInstance(ContainsValueInListStrategy.class);
|
||||
|
||||
assertEquals(valueList.getClass(), FindMD5InUserMetadata.class);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,56 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jclouds.blobstore.functions;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.http.HttpMessage;
|
||||
import org.jclouds.io.PayloadEnclosing;
|
||||
import org.jclouds.io.Payloads;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Throwables;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Singleton
|
||||
public class ObjectMD5 implements Function<Object, byte[]> {
|
||||
|
||||
public byte[] apply(Object from) {
|
||||
checkNotNull(from, "thing to md5");
|
||||
PayloadEnclosing payloadEnclosing;
|
||||
if (from instanceof PayloadEnclosing) {
|
||||
payloadEnclosing = (PayloadEnclosing) from;
|
||||
} else {
|
||||
payloadEnclosing = HttpMessage.builder().payload(Payloads.newPayload(from)).build();
|
||||
}
|
||||
if (payloadEnclosing.getPayload().getContentMetadata().getContentMD5() == null)
|
||||
try {
|
||||
Payloads.calculateMD5(payloadEnclosing);
|
||||
} catch (IOException e) {
|
||||
Throwables.propagate(e);
|
||||
}
|
||||
return payloadEnclosing.getPayload().getContentMetadata().getContentMD5();
|
||||
}
|
||||
|
||||
}
|
|
@ -1,34 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jclouds.blobstore.strategy;
|
||||
|
||||
import org.jclouds.blobstore.options.ListContainerOptions;
|
||||
import org.jclouds.blobstore.strategy.internal.FindMD5InList;
|
||||
|
||||
import com.google.inject.ImplementedBy;
|
||||
|
||||
/**
|
||||
* Determines whether a value exists in the store
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@ImplementedBy(FindMD5InList.class)
|
||||
public interface ContainsValueInListStrategy {
|
||||
|
||||
boolean execute(String containerName, Object value, ListContainerOptions options);
|
||||
|
||||
}
|
|
@ -1,66 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jclouds.blobstore.strategy.internal;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.blobstore.domain.BlobMetadata;
|
||||
import org.jclouds.blobstore.functions.ObjectMD5;
|
||||
import org.jclouds.blobstore.internal.BlobRuntimeException;
|
||||
import org.jclouds.blobstore.options.ListContainerOptions;
|
||||
import org.jclouds.blobstore.strategy.ContainsValueInListStrategy;
|
||||
import org.jclouds.blobstore.strategy.ListBlobsInContainer;
|
||||
|
||||
import com.google.common.base.Throwables;
|
||||
|
||||
/**
|
||||
* Searches Content-MD5 tag for the value associated with the value
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Singleton
|
||||
public class FindMD5InList implements ContainsValueInListStrategy {
|
||||
|
||||
protected final ObjectMD5 objectMD5;
|
||||
protected final ListBlobsInContainer getAllBlobMetadata;
|
||||
|
||||
@Inject
|
||||
private FindMD5InList(ObjectMD5 objectMD5, ListBlobsInContainer getAllBlobMetadata) {
|
||||
this.objectMD5 = objectMD5;
|
||||
this.getAllBlobMetadata = getAllBlobMetadata;
|
||||
}
|
||||
|
||||
public boolean execute(String containerName, Object value, ListContainerOptions options) {
|
||||
try {
|
||||
byte[] toSearch = objectMD5.apply(value);
|
||||
for (BlobMetadata metadata : getAllBlobMetadata.execute(containerName, options)) {
|
||||
if (Arrays.equals(toSearch, metadata.getContentMetadata().getContentMD5()))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
} catch (Exception e) {
|
||||
Throwables.propagateIfPossible(e, BlobRuntimeException.class);
|
||||
throw new BlobRuntimeException(String.format(
|
||||
"Error searching for ETAG of value: [%2$s] in container:%1$s", containerName,
|
||||
value), e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,62 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jclouds.blobstore.functions;
|
||||
|
||||
import static com.google.common.base.Charsets.UTF_8;
|
||||
import static com.google.common.hash.Hashing.md5;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.jclouds.http.HttpMessage;
|
||||
import org.jclouds.io.Payload;
|
||||
import org.jclouds.io.Payloads;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Test(groups = "unit")
|
||||
public class ObjectMD5Test {
|
||||
private ObjectMD5 fn = new ObjectMD5();
|
||||
|
||||
@Test
|
||||
public void testAlreadyHasMD5() {
|
||||
Payload payload = Payloads.newPayload("foo");
|
||||
payload.getContentMetadata().setContentMD5(new byte[] {});
|
||||
HttpMessage payloadEnclosing = HttpMessage.builder().payload(payload).build();
|
||||
assertEquals(fn.apply(payloadEnclosing), new byte[] {});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMD5PayloadEnclosing() throws IOException {
|
||||
Payload payload = Payloads.newPayload("foo");
|
||||
HttpMessage payloadEnclosing = HttpMessage.builder().payload(payload).build();
|
||||
assertEquals(fn.apply(payloadEnclosing), md5().hashString("foo", UTF_8).asBytes());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMD5String() throws IOException {
|
||||
assertEquals(fn.apply("foo"), md5().hashString("foo", UTF_8).asBytes());
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = { NullPointerException.class, IllegalStateException.class })
|
||||
public void testNullIsBad() {
|
||||
fn.apply(null);
|
||||
}
|
||||
}
|
|
@ -24,13 +24,11 @@ import org.jclouds.azureblob.AzureBlobClient;
|
|||
import org.jclouds.azureblob.blobstore.AzureAsyncBlobStore;
|
||||
import org.jclouds.azureblob.blobstore.AzureBlobRequestSigner;
|
||||
import org.jclouds.azureblob.blobstore.AzureBlobStore;
|
||||
import org.jclouds.azureblob.blobstore.strategy.FindMD5InBlobProperties;
|
||||
import org.jclouds.azureblob.domain.PublicAccess;
|
||||
import org.jclouds.blobstore.AsyncBlobStore;
|
||||
import org.jclouds.blobstore.BlobRequestSigner;
|
||||
import org.jclouds.blobstore.BlobStore;
|
||||
import org.jclouds.blobstore.attr.ConsistencyModel;
|
||||
import org.jclouds.blobstore.strategy.ContainsValueInListStrategy;
|
||||
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
import com.google.common.cache.CacheLoader;
|
||||
|
@ -51,7 +49,6 @@ public class AzureBlobStoreContextModule extends AbstractModule {
|
|||
bind(ConsistencyModel.class).toInstance(ConsistencyModel.STRICT);
|
||||
bind(AsyncBlobStore.class).to(AzureAsyncBlobStore.class).in(Scopes.SINGLETON);
|
||||
bind(BlobStore.class).to(AzureBlobStore.class).in(Scopes.SINGLETON);
|
||||
bind(ContainsValueInListStrategy.class).to(FindMD5InBlobProperties.class);
|
||||
bind(BlobRequestSigner.class).to(AzureBlobRequestSigner.class);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,72 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jclouds.azureblob.blobstore.strategy;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.azureblob.AzureBlobClient;
|
||||
import org.jclouds.azureblob.domain.BlobProperties;
|
||||
import org.jclouds.blobstore.domain.BlobMetadata;
|
||||
import org.jclouds.blobstore.functions.ObjectMD5;
|
||||
import org.jclouds.blobstore.internal.BlobRuntimeException;
|
||||
import org.jclouds.blobstore.options.ListContainerOptions;
|
||||
import org.jclouds.blobstore.strategy.ContainsValueInListStrategy;
|
||||
import org.jclouds.blobstore.strategy.ListBlobsInContainer;
|
||||
|
||||
import com.google.common.base.Throwables;
|
||||
|
||||
/**
|
||||
* Searches Content-MD5 tag for the value associated with the value
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Singleton
|
||||
public class FindMD5InBlobProperties implements ContainsValueInListStrategy {
|
||||
|
||||
protected final ObjectMD5 objectMD5;
|
||||
protected final ListBlobsInContainer getAllBlobMetadata;
|
||||
private final AzureBlobClient client;
|
||||
|
||||
@Inject
|
||||
private FindMD5InBlobProperties(ObjectMD5 objectMD5,
|
||||
ListBlobsInContainer getAllBlobMetadata, AzureBlobClient client) {
|
||||
this.objectMD5 = objectMD5;
|
||||
this.getAllBlobMetadata = getAllBlobMetadata;
|
||||
this.client = client;
|
||||
}
|
||||
|
||||
public boolean execute(String containerName, Object value, ListContainerOptions options) {
|
||||
try {
|
||||
byte[] toSearch = objectMD5.apply(value);
|
||||
for (BlobMetadata metadata : getAllBlobMetadata.execute(containerName, options)) {
|
||||
BlobProperties properties = client.getBlobProperties(containerName, metadata.getName());
|
||||
if (Arrays.equals(toSearch, properties.getContentMetadata().getContentMD5()))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
} catch (Exception e) {
|
||||
Throwables.propagateIfPossible(e, BlobRuntimeException.class);
|
||||
throw new BlobRuntimeException(String.format(
|
||||
"Error searching for ETAG of value: [%2$s] in container:%1$s", containerName,
|
||||
value), e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,45 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jclouds.azureblob.blobstore.config;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import org.jclouds.ContextBuilder;
|
||||
import org.jclouds.azureblob.AzureBlobProviderMetadata;
|
||||
import org.jclouds.azureblob.blobstore.strategy.FindMD5InBlobProperties;
|
||||
import org.jclouds.blobstore.strategy.ContainsValueInListStrategy;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.inject.Injector;
|
||||
|
||||
/**
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Test(groups = "unit")
|
||||
public class AzureBlobStoreModuleTest {
|
||||
|
||||
@Test
|
||||
void testContextImpl() {
|
||||
|
||||
Injector injector = ContextBuilder.newBuilder(new AzureBlobProviderMetadata()).credentials("foo", "bar")
|
||||
.buildInjector();
|
||||
ContainsValueInListStrategy valueList = injector.getInstance(ContainsValueInListStrategy.class);
|
||||
|
||||
assertEquals(valueList.getClass(), FindMD5InBlobProperties.class);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue