/** * Used by TEST SUITES only. Called through reflection. * * @param bucketName Bucket to delete. */ private void removeBucket(String bucketName) { init(); try { Storage.Buckets.Delete deleteBucket = storage.buckets().delete(bucketName); deleteBucket.execute(); } catch (Exception e) { throw new IgniteSpiException("Failed to remove the bucket: " + bucketName, e); } }
@Override public Policy getIamPolicy(String bucket, Map<Option, ?> options) { Span span = startSpan(HttpStorageRpcSpans.SPAN_NAME_GET_BUCKET_IAM_POLICY); Scope scope = tracer.withSpan(span); try { return storage .buckets() .getIamPolicy(bucket) .setUserProject(Option.USER_PROJECT.getString(options)) .execute(); } catch (IOException ex) { span.setStatus(Status.UNKNOWN.withDescription(ex.getMessage())); throw translate(ex); } finally { scope.close(); span.end(); } }
@Override public Policy setIamPolicy(String bucket, Policy policy, Map<Option, ?> options) { Span span = startSpan(HttpStorageRpcSpans.SPAN_NAME_SET_BUCKET_IAM_POLICY); Scope scope = tracer.withSpan(span); try { return storage .buckets() .setIamPolicy(bucket, policy) .setUserProject(Option.USER_PROJECT.getString(options)) .execute(); } catch (IOException ex) { span.setStatus(Status.UNKNOWN.withDescription(ex.getMessage())); throw translate(ex); } finally { scope.close(); span.end(); } }
@Override public TestIamPermissionsResponse testIamPermissions( String bucket, List<String> permissions, Map<Option, ?> options) { Span span = startSpan(HttpStorageRpcSpans.SPAN_NAME_TEST_BUCKET_IAM_PERMISSIONS); Scope scope = tracer.withSpan(span); try { return storage .buckets() .testIamPermissions(bucket, permissions) .setUserProject(Option.USER_PROJECT.getString(options)) .execute(); } catch (IOException ex) { span.setStatus(Status.UNKNOWN.withDescription(ex.getMessage())); throw translate(ex); } finally { scope.close(); span.end(); } }
@Override public Bucket lockRetentionPolicy(Bucket bucket, Map<Option, ?> options) { Span span = startSpan(HttpStorageRpcSpans.SPAN_LOCK_RETENTION_POLICY); Scope scope = tracer.withSpan(span); try { return storage .buckets() .lockRetentionPolicy(bucket.getName(), Option.IF_METAGENERATION_MATCH.getLong(options)) .setUserProject(Option.USER_PROJECT.getString(options)) .execute(); } catch (IOException ex) { span.setStatus(Status.UNKNOWN.withDescription(ex.getMessage())); throw translate(ex); } finally { scope.close(); span.end(); } }
@Override public Bucket create(Bucket bucket, Map<Option, ?> options) { Span span = startSpan(HttpStorageRpcSpans.SPAN_NAME_CREATE_BUCKET); Scope scope = tracer.withSpan(span); try { return storage .buckets() .insert(this.options.getProjectId(), bucket) .setProjection(DEFAULT_PROJECTION) .setPredefinedAcl(Option.PREDEFINED_ACL.getString(options)) .setPredefinedDefaultObjectAcl(Option.PREDEFINED_DEFAULT_OBJECT_ACL.getString(options)) .execute(); } catch (IOException ex) { span.setStatus(Status.UNKNOWN.withDescription(ex.getMessage())); throw translate(ex); } finally { scope.close(); span.end(); } }
@Override public boolean delete(Bucket bucket, Map<Option, ?> options) { Span span = startSpan(HttpStorageRpcSpans.SPAN_NAME_DELETE_BUCKET); Scope scope = tracer.withSpan(span); try { storage .buckets() .delete(bucket.getName()) .setIfMetagenerationMatch(Option.IF_METAGENERATION_MATCH.getLong(options)) .setIfMetagenerationNotMatch(Option.IF_METAGENERATION_NOT_MATCH.getLong(options)) .setUserProject(Option.USER_PROJECT.getString(options)) .execute(); return true; } catch (IOException ex) { span.setStatus(Status.UNKNOWN.withDescription(ex.getMessage())); StorageException serviceException = translate(ex); if (serviceException.getCode() == HTTP_NOT_FOUND) { return false; } throw serviceException; } finally { scope.close(); span.end(); } }
@Override public Bucket get(Bucket bucket, Map<Option, ?> options) { Span span = startSpan(HttpStorageRpcSpans.SPAN_NAME_GET_BUCKET); Scope scope = tracer.withSpan(span); try { return storage .buckets() .get(bucket.getName()) .setProjection(DEFAULT_PROJECTION) .setIfMetagenerationMatch(Option.IF_METAGENERATION_MATCH.getLong(options)) .setIfMetagenerationNotMatch(Option.IF_METAGENERATION_NOT_MATCH.getLong(options)) .setFields(Option.FIELDS.getString(options)) .setUserProject(Option.USER_PROJECT.getString(options)) .execute(); } catch (IOException ex) { span.setStatus(Status.UNKNOWN.withDescription(ex.getMessage())); StorageException serviceException = translate(ex); if (serviceException.getCode() == HTTP_NOT_FOUND) { return null; } throw serviceException; } finally { scope.close(); span.end(); } }
@Override public Bucket patch(Bucket bucket, Map<Option, ?> options) { Span span = startSpan(HttpStorageRpcSpans.SPAN_NAME_PATCH_BUCKET); Scope scope = tracer.withSpan(span); try { return storage .buckets() .patch(bucket.getName(), bucket) .setProjection(DEFAULT_PROJECTION) .setPredefinedAcl(Option.PREDEFINED_ACL.getString(options)) .setPredefinedDefaultObjectAcl(Option.PREDEFINED_DEFAULT_OBJECT_ACL.getString(options)) .setIfMetagenerationMatch(Option.IF_METAGENERATION_MATCH.getLong(options)) .setIfMetagenerationNotMatch(Option.IF_METAGENERATION_NOT_MATCH.getLong(options)) .setUserProject(Option.USER_PROJECT.getString(options)) .execute(); } catch (IOException ex) { span.setStatus(Status.UNKNOWN.withDescription(ex.getMessage())); throw translate(ex); } finally { scope.close(); span.end(); } }
@Override public Tuple<String, Iterable<Bucket>> list(Map<Option, ?> options) { Span span = startSpan(HttpStorageRpcSpans.SPAN_NAME_LIST_BUCKETS); Scope scope = tracer.withSpan(span); try { Buckets buckets = storage .buckets() .list(this.options.getProjectId()) .setProjection(DEFAULT_PROJECTION) .setPrefix(Option.PREFIX.getString(options)) .setMaxResults(Option.MAX_RESULTS.getLong(options)) .setPageToken(Option.PAGE_TOKEN.getString(options)) .setFields(Option.FIELDS.getString(options)) .setUserProject(Option.USER_PROJECT.getString(options)) .execute(); return Tuple.<String, Iterable<Bucket>>of(buckets.getNextPageToken(), buckets.getItems()); } catch (IOException ex) { span.setStatus(Status.UNKNOWN.withDescription(ex.getMessage())); throw translate(ex); } finally { scope.close(); span.end(); } }
public static Bucket get(Storage storage, String bucketName) throws IOException { Storage.Buckets.Get getBucket = storage.buckets().get(bucketName); getBucket.setProjection("full"); // if you are interested in acls. return getBucket.execute(); }
public static Bucket createInProject(Storage storage, String project, Bucket bucket) throws IOException { try { Storage.Buckets.Insert insertBucket = storage.buckets().insert(project, bucket); return insertBucket.execute(); } catch (GoogleJsonResponseException e) { GoogleJsonError error = e.getDetails(); if (error != null && error.getCode() == HTTP_CONFLICT && error.getMessage().contains("You already own this bucket.")) { System.out.println("already exists"); return bucket; } System.err.println(error.getMessage()); throw e; } }
/** * Fetches the metadata for the given bucket. * * @param bucketName the name of the bucket to get metadata about. * @return a Bucket containing the bucket's metadata. */ public static Bucket getBucket(String bucketName) throws IOException, GeneralSecurityException { Storage client = StorageFactory.getService(); Storage.Buckets.Get bucketRequest = client.buckets().get(bucketName); // Fetch the full set of the bucket's properties (e.g. include the ACLs in the response) bucketRequest.setProjection("full"); return bucketRequest.execute(); } // [END get_bucket]
/** * Deletes a bucket * * @param bucketName * Name of bucket to delete * @throws Exception */ public static void deleteBucket(String bucketName) throws Exception { Storage storage = getStorage(); storage.buckets().delete(bucketName).execute(); }
@Override public Boolean load(String bucketName) throws Exception { try { gcs.buckets() .testIamPermissions(bucketName, iamPermissions) .executeUnparsed() .disconnect(); } catch (IOException e) { return errorExtractor.userProjectMissing(e); } return false; } });
/** * 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; } } }
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); } }
@Override public Bucket create(Bucket bucket, Map<Option, ?> options) { try { return storage.buckets() .insert(this.options.projectId(), bucket) .setProjection(DEFAULT_PROJECTION) .setPredefinedAcl(PREDEFINED_ACL.getString(options)) .setPredefinedDefaultObjectAcl(PREDEFINED_DEFAULT_OBJECT_ACL.getString(options)) .execute(); } catch (IOException ex) { throw translate(ex); } }