本文整理了Java中com.google.api.services.storage.model.Bucket.<init>()
方法的一些代码示例,展示了Bucket.<init>()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Bucket.<init>()
方法的具体详情如下:
包路径:com.google.api.services.storage.model.Bucket
类名称:Bucket
方法名:<init>
暂无
代码示例来源:origin: googleapis/google-cloud-java
com.google.api.services.storage.model.Bucket toPb() {
com.google.api.services.storage.model.Bucket bucketPb =
new com.google.api.services.storage.model.Bucket();
bucketPb.setId(generatedId);
bucketPb.setName(name);
代码示例来源:origin: apache/ignite
Bucket newBucket = new Bucket();
代码示例来源:origin: spinnaker/kayenta
Bucket bucket = new Bucket().setName(bucketName).setVersioning(versioning);
代码示例来源:origin: google/google-api-java-client-samples
public static void main(String[] args) throws Exception {
HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport();
JsonFactory jsonFactory = JacksonFactory.getDefaultInstance();
Credential credential = CredentialsProvider.authorize(httpTransport, jsonFactory);
Storage storage = new Storage.Builder(httpTransport, jsonFactory, credential)
.setApplicationName("Google-BucketsInsertExample/1.0").build();
createInProject(storage, PROJECT_NAME, new Bucket().setName(BUCKET_NAME)
.setLocation(BUCKET_LOCATION));
}
代码示例来源:origin: google/google-api-java-client-samples
new Bucket().setName(settings.getBucket()).setLocation("US"));
代码示例来源:origin: pliablematter/simple-cloud-storage
/**
* Creates a bucket
*
* @param bucketName
* Name of bucket to create
* @throws Exception
*/
public static void createBucket(String bucketName) throws Exception {
Storage storage = getStorage();
Bucket bucket = new Bucket();
bucket.setName(bucketName);
storage.buckets().insert(
getProperties().getProperty(PROJECT_ID_PROPERTY), bucket).execute();
}
代码示例来源:origin: spinnaker/halyard
private static Bucket createBucket(Storage storage, String projectId, String locationId, String bucketId) {
try {
Bucket bucket = new Bucket()
.setLocation(locationId)
.setName(bucketId)
.setVersioning(new Bucket.Versioning().setEnabled(true));
if (!StringUtils.isEmpty(locationId)) {
bucket.setLocation(locationId);
}
return storage.buckets().insert(projectId, bucket).execute();
} catch (IOException e) {
throw new RuntimeException("Unable to create bucket", e);
}
}
代码示例来源:origin: GoogleCloudPlatform/pubsub
/**
* Creates the storage bucket used by the load test.
*/
private void createStorageBucket() throws IOException {
try {
storage.buckets().insert(projectName, new Bucket()
.setName(projectName + "-cloud-pubsub-loadtest")).execute();
} catch (GoogleJsonResponseException e) {
if (e.getStatusCode() != ALREADY_EXISTS) {
throw e;
}
}
}
代码示例来源:origin: com.netflix.spinnaker.halyard/halyard-backup
private static Bucket createBucket(Storage storage, String projectId, String locationId, String bucketId) {
try {
Bucket bucket = new Bucket()
.setLocation(locationId)
.setName(bucketId)
.setVersioning(new Bucket.Versioning().setEnabled(true));
if (!StringUtils.isEmpty(locationId)) {
bucket.setLocation(locationId);
}
return storage.buckets().insert(projectId, bucket).execute();
} catch (IOException e) {
throw new RuntimeException("Unable to create bucket", e);
}
}
代码示例来源:origin: org.apache.beam/beam-sdks-java-extensions-google-cloud-platform-core
@Test
public void testCreateBucket() throws IOException {
GcsOptions pipelineOptions = gcsOptionsWithTestCredential();
GcsUtil gcsUtil = pipelineOptions.getGcsUtil();
Storage.Buckets mockStorageObjects = Mockito.mock(Storage.Buckets.class);
Storage mockStorage = Mockito.mock(Storage.class);
gcsUtil.setStorageClient(mockStorage);
Storage.Buckets.Insert mockStorageInsert = Mockito.mock(Storage.Buckets.Insert.class);
BackOff mockBackOff = BackOffAdapter.toGcpBackOff(FluentBackoff.DEFAULT.backoff());
when(mockStorage.buckets()).thenReturn(mockStorageObjects);
when(mockStorageObjects.insert(any(String.class), any(Bucket.class)))
.thenReturn(mockStorageInsert);
when(mockStorageInsert.execute())
.thenThrow(new SocketTimeoutException("SocketException"))
.thenReturn(new Bucket());
gcsUtil.createBucket("a", new Bucket(), mockBackOff, new FastNanoClockAndSleeper());
}
代码示例来源:origin: com.google.cloud.bigdataoss/gcsio
/**
* See {@link GoogleCloudStorage#create(String, CreateBucketOptions)} for details about expected
* behavior.
*/
@Override
public void create(String bucketName, CreateBucketOptions options) throws IOException {
logger.atFine().log("create(%s)", bucketName);
Preconditions.checkArgument(
!Strings.isNullOrEmpty(bucketName), "bucketName must not be null or empty");
checkNotNull(options, "options must not be null");
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 =
configureRequest(gcs.buckets().insert(storageOptions.getProjectId(), bucket), bucketName);
// 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
}
}
代码示例来源:origin: org.apache.beam/beam-sdks-java-extensions-google-cloud-platform-core
@Test
public void testCreateBucketAccessErrors() throws IOException {
GcsOptions pipelineOptions = gcsOptionsWithTestCredential();
GcsUtil gcsUtil = pipelineOptions.getGcsUtil();
Storage mockStorage = Mockito.mock(Storage.class);
gcsUtil.setStorageClient(mockStorage);
Storage.Buckets mockStorageObjects = Mockito.mock(Storage.Buckets.class);
Storage.Buckets.Insert mockStorageInsert = Mockito.mock(Storage.Buckets.Insert.class);
BackOff mockBackOff = BackOffAdapter.toGcpBackOff(FluentBackoff.DEFAULT.backoff());
GoogleJsonResponseException expectedException =
googleJsonResponseException(
HttpStatusCodes.STATUS_CODE_FORBIDDEN,
"Waves hand mysteriously",
"These aren't the buckets you're looking for");
when(mockStorage.buckets()).thenReturn(mockStorageObjects);
when(mockStorageObjects.insert(any(String.class), any(Bucket.class)))
.thenReturn(mockStorageInsert);
when(mockStorageInsert.execute()).thenThrow(expectedException);
thrown.expect(AccessDeniedException.class);
gcsUtil.createBucket("a", new Bucket(), mockBackOff, new FastNanoClockAndSleeper());
}
代码示例来源:origin: org.apache.beam/beam-sdks-java-extensions-google-cloud-platform-core
@Test
public void testGetBucket() throws IOException {
GcsOptions pipelineOptions = gcsOptionsWithTestCredential();
GcsUtil gcsUtil = pipelineOptions.getGcsUtil();
Storage mockStorage = Mockito.mock(Storage.class);
gcsUtil.setStorageClient(mockStorage);
Storage.Buckets mockStorageObjects = Mockito.mock(Storage.Buckets.class);
Storage.Buckets.Get mockStorageGet = Mockito.mock(Storage.Buckets.Get.class);
BackOff mockBackOff = BackOffAdapter.toGcpBackOff(FluentBackoff.DEFAULT.backoff());
when(mockStorage.buckets()).thenReturn(mockStorageObjects);
when(mockStorageObjects.get("testbucket")).thenReturn(mockStorageGet);
when(mockStorageGet.execute())
.thenThrow(new SocketTimeoutException("SocketException"))
.thenReturn(new Bucket());
assertNotNull(
gcsUtil.getBucket(
GcsPath.fromComponents("testbucket", "testobject"),
mockBackOff,
new FastNanoClockAndSleeper()));
}
代码示例来源:origin: org.apache.beam/beam-sdks-java-extensions-google-cloud-platform-core
@Test
public void testBucketAccessible() throws IOException {
GcsOptions pipelineOptions = gcsOptionsWithTestCredential();
GcsUtil gcsUtil = pipelineOptions.getGcsUtil();
Storage mockStorage = Mockito.mock(Storage.class);
gcsUtil.setStorageClient(mockStorage);
Storage.Buckets mockStorageObjects = Mockito.mock(Storage.Buckets.class);
Storage.Buckets.Get mockStorageGet = Mockito.mock(Storage.Buckets.Get.class);
BackOff mockBackOff = BackOffAdapter.toGcpBackOff(FluentBackoff.DEFAULT.backoff());
when(mockStorage.buckets()).thenReturn(mockStorageObjects);
when(mockStorageObjects.get("testbucket")).thenReturn(mockStorageGet);
when(mockStorageGet.execute())
.thenThrow(new SocketTimeoutException("SocketException"))
.thenReturn(new Bucket());
assertTrue(
gcsUtil.bucketAccessible(
GcsPath.fromComponents("testbucket", "testobject"),
mockBackOff,
new FastNanoClockAndSleeper()));
}
代码示例来源:origin: org.apache.beam/beam-sdks-java-extensions-google-cloud-platform-core
Bucket bucket = new Bucket().setName(bucketName).setLocation(region);
代码示例来源:origin: com.google.cloud/google-cloud-storage
com.google.api.services.storage.model.Bucket toPb() {
com.google.api.services.storage.model.Bucket bucketPb =
new com.google.api.services.storage.model.Bucket();
bucketPb.setId(generatedId);
bucketPb.setName(name);
代码示例来源:origin: com.google.gcloud/gcloud-java-storage
com.google.api.services.storage.model.Bucket toPb() {
com.google.api.services.storage.model.Bucket bucketPb =
new com.google.api.services.storage.model.Bucket();
bucketPb.setId(generatedId);
bucketPb.setName(name);
内容来源于网络,如有侵权,请联系作者删除!