本文整理汇总了Java中com.google.api.services.storage.model.Bucket.setName方法的典型用法代码示例。如果您正苦于以下问题:Java Bucket.setName方法的具体用法?Java Bucket.setName怎么用?Java Bucket.setName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.api.services.storage.model.Bucket
的用法示例。
在下文中一共展示了Bucket.setName方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createStagingLocation
import com.google.api.services.storage.model.Bucket; //导入方法依赖的package包/类
/**
* Uses the provided specification for the staging location, creating it if it does not already
* exist. This may be a long-running blocking operation.
*/
public StagingLocationVerificationResult createStagingLocation(
String projectId, String stagingLocation, IProgressMonitor progressMonitor) {
SubMonitor monitor = SubMonitor.convert(progressMonitor, 2);
String bucketName = toGcsBucketName(stagingLocation);
if (locationIsAccessible(stagingLocation)) { // bucket already exists
return new StagingLocationVerificationResult(
String.format("Bucket %s exists", bucketName), true);
}
monitor.worked(1);
// else create the bucket
try {
Bucket newBucket = new Bucket();
newBucket.setName(bucketName);
gcsClient.buckets().insert(projectId, newBucket).execute();
return new StagingLocationVerificationResult(
String.format("Bucket %s created", bucketName), true);
} catch (GoogleJsonResponseException ex) {
GoogleJsonError error = ex.getDetails();
return new StagingLocationVerificationResult(error.getMessage(), false);
} catch (IOException e) {
return new StagingLocationVerificationResult(e.getMessage(), false);
} finally {
monitor.done();
}
}
示例2: testRetryOn401
import com.google.api.services.storage.model.Bucket; //导入方法依赖的package包/类
@Test
public void testRetryOn401() throws Exception {
final boolean sharedPublicly = false;
final boolean forFailedJobs = true;
final boolean showInline = false;
final String pathPrefix = null;
Bucket bucket = new Bucket();
bucket.setName(BUCKET_NAME);
bucket.setDefaultObjectAcl(Lists.newArrayList(new ObjectAccessControl()));
final AbstractUpload.UploadSpec uploads =
new AbstractUpload.UploadSpec(workspace,
ImmutableList.of(workspaceFile, workspaceFile2));
FakeUpload underTest = new FakeUpload(BUCKET_URI,
sharedPublicly, forFailedJobs, showInline, pathPrefix,
new MockUploadModule(executor), /* no retries */
FAKE_DETAILS,
uploads);
executor.throwWhen(Storage.Buckets.Get.class, notFoundException);
executor.passThruWhen(Storage.Buckets.Insert.class,
MockUploadModule.checkBucketName(BUCKET_NAME));
executor.passThruWhen(Storage.Objects.Insert.class,
MockUploadModule.checkObjectName(FILENAME));
executor.throwWhen(Storage.Objects.Insert.class,
httpResponseException,
MockUploadModule.checkObjectName(FILENAME2));
executor.when(Storage.Buckets.Get.class, bucket);
executor.passThruWhen(Storage.Objects.Insert.class,
MockUploadModule.checkObjectName(FILENAME2));
underTest.perform(CREDENTIALS_ID, build, TaskListener.NULL);
}
示例3: testRetryOn401StillFails
import com.google.api.services.storage.model.Bucket; //导入方法依赖的package包/类
@Test(expected = UploadException.class)
public void testRetryOn401StillFails() throws Exception {
final boolean sharedPublicly = false;
final boolean forFailedJobs = true;
final boolean showInline = false;
final String pathPrefix = null;
Bucket bucket = new Bucket();
bucket.setName(BUCKET_NAME);
bucket.setDefaultObjectAcl(Lists.newArrayList(new ObjectAccessControl()));
final AbstractUpload.UploadSpec uploads =
new AbstractUpload.UploadSpec(workspace,
ImmutableList.of(workspaceFile));
FakeUpload underTest = new FakeUpload(BUCKET_URI,
sharedPublicly, forFailedJobs, showInline, pathPrefix,
new MockUploadModule(executor), /* no retries */
FAKE_DETAILS,
uploads);
int maxRetriesPlus1 =
RetryStorageOperation.MAX_REMOTE_CREDENTIAL_EXPIRED_RETRIES + 1;
for (int i = 0; i < maxRetriesPlus1; i++) {
executor.when(Storage.Buckets.Get.class, bucket);
executor.throwWhen(Storage.Objects.Insert.class,
httpResponseException,
MockUploadModule.checkObjectName(FILENAME));
}
underTest.perform(CREDENTIALS_ID, build, TaskListener.NULL);
}
示例4: testBucketConflict
import com.google.api.services.storage.model.Bucket; //导入方法依赖的package包/类
@Test
public void testBucketConflict() throws Exception {
final boolean sharedPublicly = false;
final boolean forFailedJobs = true;
final boolean showInline = false;
final String pathPrefix = null;
final AbstractUpload.UploadSpec uploads =
new AbstractUpload.UploadSpec(workspace, ImmutableList.<FilePath>of());
FakeUpload underTest = new FakeUpload(BUCKET_URI,
sharedPublicly, forFailedJobs, showInline, pathPrefix,
new MockUploadModule(executor),
FAKE_DETAILS,
uploads);
Bucket bucket = new Bucket();
bucket.setName(BUCKET_NAME);
bucket.setDefaultObjectAcl(Lists.newArrayList(new ObjectAccessControl()));
executor.throwWhen(Storage.Buckets.Get.class, notFoundException);
executor.throwWhen(Storage.Buckets.Insert.class, conflictException,
MockUploadModule.checkBucketName(BUCKET_NAME));
executor.when(Storage.Buckets.Get.class, bucket);
underTest.perform(CREDENTIALS_ID, build, TaskListener.NULL);
}
示例5: testNotShared
import com.google.api.services.storage.model.Bucket; //导入方法依赖的package包/类
@Test
public void testNotShared() throws Exception {
final boolean sharedPublicly = false;
final boolean forFailedJobs = true;
final boolean showInline = false;
final String pathPrefix = null;
final AbstractUpload.UploadSpec uploads =
new AbstractUpload.UploadSpec(workspace,
ImmutableList.of(workspaceFile));
FakeUpload underTest = new FakeUpload(BUCKET_URI,
sharedPublicly, forFailedJobs, showInline, pathPrefix,
new MockUploadModule(executor),
FAKE_DETAILS,
uploads);
Bucket bucket = new Bucket();
bucket.setName(BUCKET_NAME);
bucket.setDefaultObjectAcl(Lists.newArrayList(new ObjectAccessControl()));
executor.when(Storage.Buckets.Get.class, bucket);
executor.passThruWhen(Storage.Objects.Insert.class,
new Predicate<Storage.Objects.Insert>() {
@Override
public boolean apply(Storage.Objects.Insert operation) {
StorageObject object = (StorageObject) operation.getJsonContent();
assertNull(object.getAcl());
return true;
}
});
underTest.perform(CREDENTIALS_ID, build, TaskListener.NULL);
}
示例6: create
import com.google.api.services.storage.model.Bucket; //导入方法依赖的package包/类
/**
* See {@link GoogleCloudStorage#create(String, CreateBucketOptions)} for
* details about expected behavior.
*/
@Override
public void create(String bucketName, CreateBucketOptions options)
throws IOException {
LOG.debug("create({})", bucketName);
Preconditions.checkArgument(!Strings.isNullOrEmpty(bucketName),
"bucketName must not be null or empty");
Preconditions.checkNotNull(options, "options must not be null");
Preconditions.checkNotNull(storageOptions.getProjectId(), "projectId must not be null");
Bucket bucket = new Bucket();
bucket.setName(bucketName);
bucket.setLocation(options.getLocation());
bucket.setStorageClass(options.getStorageClass());
Storage.Buckets.Insert insertBucket =
gcs.buckets().insert(storageOptions.getProjectId(), bucket);
// TODO(user): To match the behavior of throwing FileNotFoundException for 404, we probably
// want to throw org.apache.commons.io.FileExistsException for 409 here.
try {
ResilientOperation.retry(
ResilientOperation.getGoogleRequestCallable(insertBucket),
backOffFactory.newBackOff(),
rateLimitedRetryDeterminer,
IOException.class,
sleeper);
} catch (InterruptedException e) {
throw new IOException(e); // From sleep
}
}
示例7: createTestBucket
import com.google.api.services.storage.model.Bucket; //导入方法依赖的package包/类
/**
* Creates a test bucket based on the given number.
*/
private Bucket createTestBucket(int bucketNumber) {
Bucket b = new Bucket();
String bucketNumberStr = Integer.toString(bucketNumber);
b.setName("bucket" + bucketNumberStr);
b.setTimeCreated(new DateTime(new Date()));
b.setLocation("location");
b.setStorageClass("DRA");
return b;
}
示例8: testSharedPublicly
import com.google.api.services.storage.model.Bucket; //导入方法依赖的package包/类
@Test
public void testSharedPublicly() throws Exception {
final boolean sharedPublicly = true;
final boolean forFailedJobs = true;
final boolean showInline = false;
final String pathPrefix = null;
final AbstractUpload.UploadSpec uploads =
new AbstractUpload.UploadSpec(workspace,
ImmutableList.of(workspaceFile));
FakeUpload underTest = new FakeUpload(BUCKET_URI,
sharedPublicly, forFailedJobs, showInline, pathPrefix,
new MockUploadModule(executor),
FAKE_DETAILS,
uploads);
final Bucket bucket = new Bucket();
bucket.setName(BUCKET_NAME);
bucket.setDefaultObjectAcl(Lists.newArrayList(new ObjectAccessControl()));
executor.when(Storage.Buckets.Get.class, bucket);
executor.passThruWhen(Storage.Objects.Insert.class,
new Predicate<Storage.Objects.Insert>() {
@Override
public boolean apply(Storage.Objects.Insert operation) {
StorageObject object = (StorageObject) operation.getJsonContent();
assertTrue(object.getAcl().containsAll(
bucket.getDefaultObjectAcl()));
List<ObjectAccessControl> addedAcl =
Lists.newArrayList(Iterables.filter(
object.getAcl(), not(in(bucket.getDefaultObjectAcl()))));
Set<String> addedEntities = Sets.newHashSet();
for (ObjectAccessControl access : addedAcl) {
assertEquals("READER", access.getRole());
addedEntities.add(access.getEntity());
}
assertTrue(addedEntities.contains("allUsers"));
return true;
}
});
underTest.perform(CREDENTIALS_ID, build, TaskListener.NULL);
}