本文整理汇总了Java中org.jclouds.blobstore.BlobStore.createContainerInLocation方法的典型用法代码示例。如果您正苦于以下问题:Java BlobStore.createContainerInLocation方法的具体用法?Java BlobStore.createContainerInLocation怎么用?Java BlobStore.createContainerInLocation使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jclouds.blobstore.BlobStore
的用法示例。
在下文中一共展示了BlobStore.createContainerInLocation方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testListContainer
import org.jclouds.blobstore.BlobStore; //导入方法依赖的package包/类
@Test
public void testListContainer() throws Exception {
String containerName = Utils.createRandomContainerName();
String blobName = UtilsTest.createRandomBlobName();
BlobStore blobStore = app.getBlobStore(objectStoreId);
blobStore.createContainerInLocation(null, containerName);
Blob blob = UtilsTest.makeBlob(blobStore, blobName);
blobStore.putBlob(containerName, blob);
HttpURLConnection connection = UtilsTest.submitRequest(containerAPI + "/" + containerName,
HttpMethod.GET, null);
assertThat(connection.getResponseCode()).isEqualTo(Response.Status.OK.getStatusCode());
try (InputStream stream = connection.getInputStream()) {
ContainerResource.Container container = new ObjectMapper().readValue(stream,
ContainerResource.Container.class);
assertThat(container.objects).hasSize(1);
assertThat(container.objects.get(0).name).isEqualTo(blobName);
}
}
示例2: testRecursiveList
import org.jclouds.blobstore.BlobStore; //导入方法依赖的package包/类
@Test
public void testRecursiveList() throws Exception {
String container = Utils.createRandomContainerName();
BlobStore blobStore = app.getBlobStore(objectStoreId);
blobStore.createContainerInLocation(null, container);
String blob = "foo/bar";
String blob2 = "foo/baz";
blobStore.putBlob(container, UtilsTest.makeBlob(blobStore, blob));
blobStore.putBlob(container, UtilsTest.makeBlob(blobStore, blob2));
HttpURLConnection connection = UtilsTest.submitRequest(containerAPI + "/" + container, HttpMethod.GET, null);
assertThat(connection.getResponseCode()).isEqualTo(Response.Status.OK.getStatusCode());
try (InputStream stream = connection.getInputStream()) {
ContainerResource.Container resultContainer = new ObjectMapper().readValue(stream,
ContainerResource.Container.class);
assertThat(resultContainer.objects).hasSize(2);
assertThat(resultContainer.objects.get(0).name).isEqualTo(blob);
assertThat(resultContainer.objects.get(1).name).isEqualTo(blob2);
}
}
示例3: testConfigMoveEverythingPolicy
import org.jclouds.blobstore.BlobStore; //导入方法依赖的package包/类
@Test
public void testConfigMoveEverythingPolicy() throws Exception {
setTransientBackend();
app.getBlobStore(0).createContainerInLocation(null, containerName);
app.getBlobStore(1).createContainerInLocation(null, containerName);
BlobStore blobStore = app.getBlobStore(0);
blobStore.createContainerInLocation(null, containerName);
blobStore.putBlob(containerName,
UtilsTest.makeBlob(blobStore, UtilsTest.createRandomBlobName()));
configureMoveEverythingPolicy();
blobStore = app.getBlobStore(containerName);
blobStore.createContainerInLocation(null, containerName);
BounceService.BounceTaskStatus status = bounceService.bounce(containerName);
status.future().get();
assertStatus(status, status::getTotalObjectCount).isEqualTo(1);
assertStatus(status, status::getMovedObjectCount).isEqualTo(1);
assertStatus(status, status::getErrorObjectCount).isEqualTo(0);
}
示例4: setUp
import org.jclouds.blobstore.BlobStore; //导入方法依赖的package包/类
@Before
public void setUp() throws Exception {
ContextBuilder builder = ContextBuilder
.newBuilder("transient")
.credentials("identity", "credential")
.modules(ImmutableList.<Module>of(new SLF4JLoggingModule()));
context = builder.build(BlobStoreContext.class);
contextRead = builder.build(BlobStoreContext.class);
BlobStore blobStore = context.getBlobStore();
BlobStore blobStoreRead = contextRead.getBlobStore();
String containerName = "container-name";
Location location = null;
blobStore.createContainerInLocation(location, containerName);
blobStoreRead.createContainerInLocation(location, containerName);
awcyStrong = new AreWeConsistentYet(blobStore,
blobStore, containerName, ITERATIONS, OBJECT_SIZE);
awcyEventual = new AreWeConsistentYet(blobStore,
blobStoreRead, containerName, ITERATIONS, OBJECT_SIZE);
}
示例5: uploadSourceBlob
import org.jclouds.blobstore.BlobStore; //导入方法依赖的package包/类
private void uploadSourceBlob() {
BlobStore blobStore = app.getBlobStore(0);
String blobName = UtilsTest.createRandomBlobName();
byte[] blobContent = "foo".getBytes();
blob = UtilsTest.makeBlob(blobStore, blobName, ByteSource.wrap(blobContent));
blobStore.createContainerInLocation(null, container);
blobStore.putBlob(container, blob);
}
示例6: createOrRequestContainer
import org.jclouds.blobstore.BlobStore; //导入方法依赖的package包/类
public static String createOrRequestContainer(BlobStore blobStore) {
String container;
if (!isTransient(blobStore)) {
container = ContainerPool.getContainerPool(blobStore).getContainer();
} else {
container = Utils.createRandomContainerName();
blobStore.createContainerInLocation(null, container);
}
return container;
}
示例7: setUpClass
import org.jclouds.blobstore.BlobStore; //导入方法依赖的package包/类
@BeforeClass
public static void setUpClass() throws Exception {
BlobStore blobStore = ContextBuilder.newBuilder("transient").credentials("id", "credential").buildView(BlobStoreContext.class).getBlobStore();
blobStore.createContainerInLocation(null, "foo");
blobStore.createContainerInLocation(null, "bar");
}
示例8: activateService
import org.jclouds.blobstore.BlobStore; //导入方法依赖的package包/类
@Override
public void activateService()
throws Exception
{
configuration.refresh();
String provider = configuration.get().provider().get();
String identifier = configuration.get().identifier().get();
String credentials = configuration.get().credential().get();
String endpoint = configuration.get().endpoint().get();
Map<String, String> properties = configuration.get().properties().get();
container = configuration.get().container().get();
if( provider != null )
{
checkArgument( contains( allKeys, provider ), "provider %s not in supported list: %s", provider, allKeys );
}
else
{
provider = "transient";
}
if( container == null )
{
container = "polygene-entities";
}
storeContext = ContextBuilder.newBuilder( provider )
.endpoint( endpoint == null ? "" : endpoint )
.credentials( identifier, credentials )
.overrides( asProperties( properties ) )
.buildView( BlobStoreContext.class );
BlobStore blobStore = storeContext.getBlobStore();
if( !blobStore.containerExists( container ) )
{
if( !blobStore.createContainerInLocation( null, container ) )
{
throw new EntityStoreException( "Unable to create JClouds Blob Container, cannot continue." );
}
else
{
LOGGER.debug( "Created new container: {}", container );
}
}
LOGGER.info( "Activated using {} cloud provider [id:{}]", provider, identifier );
}
示例9: createContainer
import org.jclouds.blobstore.BlobStore; //导入方法依赖的package包/类
public void createContainer(BlobStore blobStore) {
blobStore.createContainerInLocation(null, bucketName);
}
示例10: setUp
import org.jclouds.blobstore.BlobStore; //导入方法依赖的package包/类
@Before
public void setUp() throws Exception {
Properties s3ProxyProperties = new Properties();
InputStream is = Resources.asByteSource(Resources.getResource(
"s3proxy.conf")).openStream();
try {
s3ProxyProperties.load(is);
} finally {
is.close();
}
String provider = s3ProxyProperties.getProperty(
Constants.PROPERTY_PROVIDER);
String identity = s3ProxyProperties.getProperty(
Constants.PROPERTY_IDENTITY);
String credential = s3ProxyProperties.getProperty(
Constants.PROPERTY_CREDENTIAL);
String endpoint = s3ProxyProperties.getProperty(
Constants.PROPERTY_ENDPOINT);
String s3Identity = s3ProxyProperties.getProperty(
S3ProxyConstants.PROPERTY_IDENTITY);
String s3Credential = s3ProxyProperties.getProperty(
S3ProxyConstants.PROPERTY_CREDENTIAL);
awsCreds = new BasicAWSCredentials(s3Identity, s3Credential);
s3Endpoint = new URI(s3ProxyProperties.getProperty(
S3ProxyConstants.PROPERTY_ENDPOINT));
String keyStorePath = s3ProxyProperties.getProperty(
S3ProxyConstants.PROPERTY_KEYSTORE_PATH);
String keyStorePassword = s3ProxyProperties.getProperty(
S3ProxyConstants.PROPERTY_KEYSTORE_PASSWORD);
String virtualHost = s3ProxyProperties.getProperty(
S3ProxyConstants.PROPERTY_VIRTUAL_HOST);
ContextBuilder builder = ContextBuilder
.newBuilder(provider)
.credentials(identity, credential)
.modules(ImmutableList.<Module>of(new SLF4JLoggingModule()))
.overrides(s3ProxyProperties);
if (!Strings.isNullOrEmpty(endpoint)) {
builder.endpoint(endpoint);
}
context = builder.build(BlobStoreContext.class);
BlobStore blobStore = context.getBlobStore();
containerName = createRandomContainerName();
key = "stuff";
blobStore.createContainerInLocation(null, containerName);
S3Proxy.Builder s3ProxyBuilder = S3Proxy.builder()
.blobStore(blobStore)
.endpoint(s3Endpoint);
if (s3Identity != null || s3Credential != null) {
s3ProxyBuilder.awsAuthentication(s3Identity, s3Credential);
}
if (keyStorePath != null || keyStorePassword != null) {
s3ProxyBuilder.keyStore(
Resources.getResource(keyStorePath).toString(),
keyStorePassword);
}
if (virtualHost != null) {
s3ProxyBuilder.virtualHost(virtualHost);
}
s3Proxy = s3ProxyBuilder.build();
s3Proxy.start();
while (!s3Proxy.getState().equals(AbstractLifeCycle.STARTED)) {
Thread.sleep(1);
}
// reset endpoint to handle zero port
s3Endpoint = new URI(s3Endpoint.getScheme(), s3Endpoint.getUserInfo(),
s3Endpoint.getHost(), s3Proxy.getPort(), s3Endpoint.getPath(),
s3Endpoint.getQuery(), s3Endpoint.getFragment());
}
示例11: handleContainerCreate
import org.jclouds.blobstore.BlobStore; //导入方法依赖的package包/类
private static void handleContainerCreate(HttpServletRequest request,
HttpServletResponse response, InputStream is, BlobStore blobStore,
String containerName) throws IOException, S3Exception {
if (containerName.isEmpty()) {
throw new S3Exception(S3ErrorCode.METHOD_NOT_ALLOWED);
}
String contentLengthString = request.getHeader(
HttpHeaders.CONTENT_LENGTH);
if (contentLengthString != null) {
long contentLength;
try {
contentLength = Long.parseLong(contentLengthString);
} catch (NumberFormatException nfe) {
throw new S3Exception(S3ErrorCode.INVALID_ARGUMENT, nfe);
}
if (contentLength < 0) {
throw new S3Exception(S3ErrorCode.INVALID_ARGUMENT);
}
}
String locationString;
try (PushbackInputStream pis = new PushbackInputStream(is)) {
int ch = pis.read();
if (ch == -1) {
// handle empty bodies
locationString = null;
} else {
pis.unread(ch);
CreateBucketRequest cbr = new XmlMapper().readValue(
pis, CreateBucketRequest.class);
locationString = cbr.locationConstraint;
}
}
Location location = null;
if (locationString != null) {
for (Location loc : blobStore.listAssignableLocations()) {
if (loc.getId().equalsIgnoreCase(locationString)) {
location = loc;
break;
}
}
if (location == null) {
throw new S3Exception(S3ErrorCode.INVALID_LOCATION_CONSTRAINT);
}
}
logger.debug("Creating bucket with location: {}", location);
CreateContainerOptions options = new CreateContainerOptions();
String acl = request.getHeader("x-amz-acl");
if ("public-read".equalsIgnoreCase(acl)) {
options.publicRead();
}
boolean created;
try {
created = blobStore.createContainerInLocation(location,
containerName, options);
} catch (AuthorizationException ae) {
if (ae.getCause() instanceof AccessDeniedException) {
throw new S3Exception(S3ErrorCode.ACCESS_DENIED,
"Could not create bucket", ae);
}
throw new S3Exception(S3ErrorCode.BUCKET_ALREADY_EXISTS, ae);
}
if (!created) {
throw new S3Exception(S3ErrorCode.BUCKET_ALREADY_OWNED_BY_YOU,
S3ErrorCode.BUCKET_ALREADY_OWNED_BY_YOU.getMessage(),
null, ImmutableMap.of("BucketName", containerName));
}
response.addHeader(HttpHeaders.LOCATION, "/" + containerName);
}
示例12: createContainer
import org.jclouds.blobstore.BlobStore; //导入方法依赖的package包/类
@POST
@Timed
@Consumes(MediaType.APPLICATION_JSON)
public Response createContainer(@PathParam("id") int providerId, Map<String, String> request) {
BlobStore blobStore = app.getBlobStore(providerId);
if (blobStore == null) {
throw new WebApplicationException(Response.Status.NOT_FOUND);
}
if (!request.containsKey("name")) {
throw new WebApplicationException(Response.Status.BAD_REQUEST);
}
ObjectStore store = getStoreById(providerId, app.getConfiguration());
if (store.getStorageClass() == null && store.getRegion() == null) {
blobStore.createContainerInLocation(null, request.get("name"));
return Response.ok().build();
}
switch (store.getProvider()) {
case "google-cloud-storage":
GoogleCloudStorageApi api = blobStore.getContext().unwrapApi(GoogleCloudStorageApi.class);
BucketApi bucketApi = api.getBucketApi();
BucketTemplate template = new BucketTemplate().name(request.get("name"))
.location(DomainResourceReferences.Location.valueOf(store.getRegion()))
.storageClass(DomainResourceReferences.StorageClass.valueOf(store.translateStorageClass()));
Bucket bucket = bucketApi.createBucket(store.translateIdentity(), template);
if (bucket == null) {
return Response.status(Response.Status.CONFLICT).build();
}
break;
case "aws-s3":
try {
if (!blobStore.createContainerInLocation(getLocation(blobStore, store.getRegion()), request.get("name"))) {
return Response.status(Response.Status.BAD_REQUEST).build();
}
} catch (ResourceAlreadyExistsException e) {
return Response.status(Response.Status.CONFLICT).build();
}
break;
default:
return Response.status(Response.Status.BAD_REQUEST).build();
}
return Response.ok().build();
}
示例13: testRandomOperations
import org.jclouds.blobstore.BlobStore; //导入方法依赖的package包/类
@Test
public void testRandomOperations() throws Exception {
BlobStore reference = UtilsTest.createTransientBlobStore();
reference.createContainerInLocation(null, containerName);
final int baseNumTest = 100;
Random r = new Random();
if (System.getProperty("TEST_SEED") != null) {
r.setSeed(Long.valueOf(System.getProperty("TEST_SEED")));
} else {
long seed = new Random().nextLong();
logger.info("seed: {}", seed);
r.setSeed(seed);
}
int objectCount = baseNumTest + r.nextInt(baseNumTest);
ArrayList<String> blobNames = new ArrayList<>(objectCount);
for (int i = 0; i < objectCount; i++) {
blobNames.add("blob-" + r.nextInt(Integer.MAX_VALUE));
}
List<BlobStore> blobStores = ImmutableList.of(reference, policy);
int numBlobsInStore = 0;
int opsCount = baseNumTest + r.nextInt(baseNumTest);
for (int i = 0; i < opsCount; i++) {
String blobName = blobNames.get(r.nextInt(blobNames.size()));
int op = r.nextInt(3);
if (op == 0) {
// PUT
int blobLen = 1000 + r.nextInt(1000);
blobStores.forEach(b -> {
Blob blob = UtilsTest.makeBlob(b, blobName, ByteSource.wrap(new byte[blobLen]));
b.putBlob(containerName, blob);
});
numBlobsInStore++;
} else if (op == 1) {
// GET
Blob one = reference.getBlob(containerName, blobName);
Blob two = policy.getBlob(containerName, blobName);
UtilsTest.assertEqualBlobs(two, one);
} else if (op == 2) {
// DELETE
blobStores.forEach(b -> b.removeBlob(containerName, blobName));
}
}
assertEqualBlobStores(reference, policy);
BounceService.BounceTaskStatus status = runBounce(bounceService, containerName);
if (policy.getDestination() instanceof BouncePolicy) {
assertStatus(status, status::getTotalObjectCount).isLessThanOrEqualTo(numBlobsInStore * 2);
} else {
assertStatus(status, status::getTotalObjectCount).isLessThanOrEqualTo(numBlobsInStore);
}
numBlobsInStore = (int) status.getTotalObjectCount();
assertStatus(status, status::getCopiedObjectCount).isEqualTo(numBlobsInStore);
assertEqualBlobStores(reference, policy);
UtilsTest.advanceServiceClock(app, duration.plusSeconds(1));
status = runBounce(bounceService, containerName);
assertStatus(status, status::getTotalObjectCount).isEqualTo(numBlobsInStore);
assertThat(status.getLinkedObjectCount() + status.getMovedObjectCount()).isEqualTo(numBlobsInStore);
}
示例14: testListWithVirtualContainer
import org.jclouds.blobstore.BlobStore; //导入方法依赖的package包/类
@Test
public void testListWithVirtualContainer() throws Exception {
String cacheContainer = Utils.createRandomContainerName();
String originContainer = Utils.createRandomContainerName();
String virtualContainerName = Utils.createRandomContainerName();
BlobStore blobStore = app.getBlobStore(objectStoreId);
blobStore.createContainerInLocation(null, originContainer);
blobStore.createContainerInLocation(null, cacheContainer);
Properties newProperties = new Properties();
String prefix = VirtualContainerResource.VIRTUAL_CONTAINER_PREFIX + ".0";
Map<String, String> settings = new ImmutableMap.Builder<String, String>()
.put(prefix + ".name", virtualContainerName)
.put(Joiner.on(".").join(prefix, VirtualContainer.CACHE_TIER_PREFIX, Location.BLOB_STORE_ID_FIELD),
Integer.toString(objectStoreId))
.put(Joiner.on(".").join(prefix, VirtualContainer.CACHE_TIER_PREFIX, Location.CONTAINER_NAME_FIELD),
cacheContainer)
.put(Joiner.on(".").join(prefix, VirtualContainer.CACHE_TIER_PREFIX, "policy"),
WriteBackPolicy.class.getSimpleName())
.put(Joiner.on(".").join(prefix, VirtualContainer.CACHE_TIER_PREFIX, "evictDelay"),
Duration.ofHours(1).toString())
.put(Joiner.on(".").join(prefix, VirtualContainer.CACHE_TIER_PREFIX, "copyDelay"),
Duration.ofHours(0).toString())
.put(Joiner.on(".").join(prefix, VirtualContainer.PRIMARY_TIER_PREFIX, Location.BLOB_STORE_ID_FIELD),
Integer.toString(objectStoreId))
.put(Joiner.on(".").join(prefix, VirtualContainer.PRIMARY_TIER_PREFIX, Location.CONTAINER_NAME_FIELD),
originContainer)
.build();
newProperties.putAll(settings);
new ConfigurationResource(app).updateConfig(newProperties);
String blobName = UtilsTest.createRandomBlobName();
BlobStore vBlobStore = app.getBlobStore(virtualContainerName);
Blob blob = UtilsTest.makeBlob(vBlobStore, blobName);
vBlobStore.putBlob(virtualContainerName, blob);
HttpURLConnection connection = UtilsTest.submitRequest(containerAPI + "/" + virtualContainerName,
HttpMethod.GET, null);
assertThat(connection.getResponseCode()).isEqualTo(Response.Status.OK.getStatusCode());
try (InputStream stream = connection.getInputStream()) {
ContainerResource.Container container = new ObjectMapper().readValue(stream,
ContainerResource.Container.class);
assertThat(container.objects).hasSize(1);
assertThat(container.objects.get(0).name).isEqualTo(blobName);
}
}
示例15: main
import org.jclouds.blobstore.BlobStore; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
Options options = new Options();
CmdLineParser parser = new CmdLineParser(options);
try {
parser.parseArgument(args);
} catch (CmdLineException cle) {
PrintStream err = System.err;
err.println("are-we-consistent-yet version " +
AreWeConsistentYet.class.getPackage()
.getImplementationVersion());
err.println("Usage: are-we-consistent-yet" +
" --container-name NAME --properties FILE [options...]");
parser.printUsage(err);
System.exit(1);
}
Properties properties = new Properties();
try (InputStream is = new FileInputStream(options.propertiesFile)) {
properties.load(is);
}
Properties propertiesRead = (Properties) properties.clone();
if (options.readerEndpoint != null) {
propertiesRead.setProperty(Constants.PROPERTY_ENDPOINT,
options.readerEndpoint);
}
try (BlobStoreContext context = blobStoreContextFromProperties(
properties);
BlobStoreContext contextRead = blobStoreContextFromProperties(
propertiesRead)) {
BlobStore blobStore = context.getBlobStore();
BlobStore blobStoreRead = contextRead.getBlobStore();
Location location = null;
if (options.location != null) {
for (Location loc : blobStore.listAssignableLocations()) {
if (loc.getId().equalsIgnoreCase(options.location)) {
location = loc;
break;
}
}
if (location == null) {
throw new Exception("Could not find location: " +
options.location);
}
}
blobStore.createContainerInLocation(location,
options.containerName);
AreWeConsistentYet test = new AreWeConsistentYet(
blobStore, blobStoreRead, options.containerName,
options.iterations, options.objectSize);
PrintStream out = System.out;
out.println("eventual consistency count with " +
options.iterations + " iterations: ");
out.println("read after create: " + test.readAfterCreate());
out.println("read after delete: " + test.readAfterDelete());
out.println("read after overwrite: " + test.readAfterOverwrite());
out.println("list after create: " + test.listAfterCreate());
out.println("list after delete: " + test.listAfterDelete());
blobStore.deleteContainer(options.containerName);
}
}