log.warn("Bucket {} does not exist. Creating it in project {}.", bucketName, projectName); Bucket.Versioning versioning = new Bucket.Versioning().setEnabled(true); Bucket bucket = new Bucket().setName(bucketName).setVersioning(versioning);
builder.setVersioningEnabled(bucketPb.getVersioning().getEnabled());
bucketPb.setVersioning(new Versioning().setEnabled(versioningEnabled));
builder.setVersioningEnabled(bucketPb.getVersioning().getEnabled());
builder.versioningEnabled(bucketPb.getVersioning().getEnabled());
bucketPb.setVersioning(new Versioning().setEnabled(versioningEnabled));
private static void ensureBucketExistsAndVersioned(Storage storage, String projectId, String locationId, String bucketId) { Bucket bucket; try { bucket = storage.buckets().get(bucketId).execute(); } catch (GoogleJsonResponseException e) { if (e.getStatusCode() == 404) { bucket = createBucket(storage, projectId, locationId, bucketId); } else { throw new RuntimeException("Can't retrieve bucket", e); } } catch (IOException e) { throw new RuntimeException("Can't retrieve bucket", e); } if (!bucket.getVersioning().getEnabled()) { throw new RuntimeException("Bucket " + bucketId + " is not versioned. Aborting."); } }
private static void ensureBucketExistsAndVersioned(Storage storage, String projectId, String locationId, String bucketId) { Bucket bucket; try { bucket = storage.buckets().get(bucketId).execute(); } catch (GoogleJsonResponseException e) { if (e.getStatusCode() == 404) { bucket = createBucket(storage, projectId, locationId, bucketId); } else { throw new RuntimeException("Can't retrieve bucket", e); } } catch (IOException e) { throw new RuntimeException("Can't retrieve bucket", e); } if (!bucket.getVersioning().getEnabled()) { throw new RuntimeException("Bucket " + bucketId + " is not versioned. Aborting."); } }
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); } }
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); } }
bucketPb.setVersioning(new Versioning().setEnabled(versioningEnabled));