Search in sources :

Example 1 with GcpGcsBucketLifecycleRule

use of bio.terra.workspace.model.GcpGcsBucketLifecycleRule in project terra-cli by DataBiosphere.

the class WorkspaceManagerService method fromCLIObject.

/**
 * This method converts this CLI-defined POJO class into a list of WSM client library-defined
 * request objects.
 *
 * @return list of lifecycle rules in the format expected by the WSM client library
 */
private static List<GcpGcsBucketLifecycleRule> fromCLIObject(GcsBucketLifecycle lifecycle) {
    List<GcpGcsBucketLifecycleRule> wsmLifecycleRules = new ArrayList<>();
    for (GcsBucketLifecycle.Rule rule : lifecycle.rule) {
        GcpGcsBucketLifecycleRuleAction action = new GcpGcsBucketLifecycleRuleAction().type(rule.action.type.toWSMEnum());
        if (rule.action.storageClass != null) {
            action.storageClass(rule.action.storageClass.toWSMEnum());
        }
        GcpGcsBucketLifecycleRuleCondition condition = new GcpGcsBucketLifecycleRuleCondition().age(rule.condition.age).createdBefore(dateAtMidnightAndUTC(rule.condition.createdBefore)).customTimeBefore(dateAtMidnightAndUTC(rule.condition.customTimeBefore)).daysSinceCustomTime(rule.condition.daysSinceCustomTime).daysSinceNoncurrentTime(rule.condition.daysSinceNoncurrentTime).live(rule.condition.isLive).matchesStorageClass(rule.condition.matchesStorageClass.stream().map(GcsStorageClass::toWSMEnum).collect(Collectors.toList())).noncurrentTimeBefore(dateAtMidnightAndUTC(rule.condition.noncurrentTimeBefore)).numNewerVersions(rule.condition.numNewerVersions);
        GcpGcsBucketLifecycleRule lifecycleRuleRequestObject = new GcpGcsBucketLifecycleRule().action(action).condition(condition);
        wsmLifecycleRules.add(lifecycleRuleRequestObject);
    }
    return wsmLifecycleRules;
}
Also used : GcsStorageClass(bio.terra.cli.serialization.userfacing.input.GcsStorageClass) GcpGcsBucketLifecycleRuleCondition(bio.terra.workspace.model.GcpGcsBucketLifecycleRuleCondition) GcpGcsBucketLifecycleRuleAction(bio.terra.workspace.model.GcpGcsBucketLifecycleRuleAction) GcpGcsBucketLifecycleRule(bio.terra.workspace.model.GcpGcsBucketLifecycleRule) ArrayList(java.util.ArrayList) GcsBucketLifecycle(bio.terra.cli.serialization.userfacing.input.GcsBucketLifecycle) GcpGcsBucketLifecycle(bio.terra.workspace.model.GcpGcsBucketLifecycle)

Example 2 with GcpGcsBucketLifecycleRule

use of bio.terra.workspace.model.GcpGcsBucketLifecycleRule in project terra-cli by DataBiosphere.

the class WorkspaceManagerService method updateControlledGcsBucket.

/**
 * Call the Workspace Manager POST
 * "/api/workspaces/v1/{workspaceId}/resources/controlled/gcp/buckets/{resourceId}" endpoint to
 * update a GCS bucket controlled resource in the workspace.
 *
 * @param workspaceId the workspace where the resource exists
 * @param resourceId the resource id
 * @param updateParams resource properties to update
 */
public void updateControlledGcsBucket(UUID workspaceId, UUID resourceId, UpdateControlledGcsBucketParams updateParams) {
    // convert the CLI lifecycle rule object into the WSM request objects
    List<GcpGcsBucketLifecycleRule> lifecycleRules = fromCLIObject(updateParams.lifecycle);
    // convert the CLI object to a WSM request object
    UpdateControlledGcpGcsBucketRequestBody updateRequest = new UpdateControlledGcpGcsBucketRequestBody().name(updateParams.resourceFields.name).description(updateParams.resourceFields.description).updateParameters(new GcpGcsBucketUpdateParameters().defaultStorageClass(updateParams.defaultStorageClass).lifecycle(new GcpGcsBucketLifecycle().rules(lifecycleRules)));
    callWithRetries(() -> new ControlledGcpResourceApi(apiClient).updateGcsBucket(updateRequest, workspaceId, resourceId), "Error updating controlled GCS bucket in the workspace.");
}
Also used : GcpGcsBucketLifecycleRule(bio.terra.workspace.model.GcpGcsBucketLifecycleRule) UpdateControlledGcpGcsBucketRequestBody(bio.terra.workspace.model.UpdateControlledGcpGcsBucketRequestBody) ControlledGcpResourceApi(bio.terra.workspace.api.ControlledGcpResourceApi) GcpGcsBucketUpdateParameters(bio.terra.workspace.model.GcpGcsBucketUpdateParameters) GcpGcsBucketLifecycle(bio.terra.workspace.model.GcpGcsBucketLifecycle)

Example 3 with GcpGcsBucketLifecycleRule

use of bio.terra.workspace.model.GcpGcsBucketLifecycleRule in project terra-cli by DataBiosphere.

the class WorkspaceManagerService method createControlledGcsBucket.

/**
 * Call the Workspace Manager POST
 * "/api/workspaces/v1/{workspaceId}/resources/controlled/gcp/buckets" endpoint to add a GCS
 * bucket as a controlled resource in the workspace.
 *
 * @param workspaceId the workspace to add the resource to
 * @param createParams creation parameters
 * @return the GCS bucket resource object
 */
public GcpGcsBucketResource createControlledGcsBucket(UUID workspaceId, CreateGcsBucketParams createParams) {
    // convert the CLI lifecycle rule object into the WSM request objects
    List<GcpGcsBucketLifecycleRule> lifecycleRules = fromCLIObject(createParams.lifecycle);
    // convert the CLI object to a WSM request object
    CreateControlledGcpGcsBucketRequestBody createRequest = new CreateControlledGcpGcsBucketRequestBody().common(createCommonFields(createParams.resourceFields)).gcsBucket(new GcpGcsBucketCreationParameters().name(createParams.bucketName).defaultStorageClass(createParams.defaultStorageClass).lifecycle(new GcpGcsBucketLifecycle().rules(lifecycleRules)).location(createParams.location));
    return callWithRetries(() -> new ControlledGcpResourceApi(apiClient).createBucket(createRequest, workspaceId).getGcpBucket(), "Error creating controlled GCS bucket in the workspace.");
}
Also used : GcpGcsBucketCreationParameters(bio.terra.workspace.model.GcpGcsBucketCreationParameters) GcpGcsBucketLifecycleRule(bio.terra.workspace.model.GcpGcsBucketLifecycleRule) CreateControlledGcpGcsBucketRequestBody(bio.terra.workspace.model.CreateControlledGcpGcsBucketRequestBody) ControlledGcpResourceApi(bio.terra.workspace.api.ControlledGcpResourceApi) GcpGcsBucketLifecycle(bio.terra.workspace.model.GcpGcsBucketLifecycle)

Aggregations

GcpGcsBucketLifecycle (bio.terra.workspace.model.GcpGcsBucketLifecycle)3 GcpGcsBucketLifecycleRule (bio.terra.workspace.model.GcpGcsBucketLifecycleRule)3 ControlledGcpResourceApi (bio.terra.workspace.api.ControlledGcpResourceApi)2 GcsBucketLifecycle (bio.terra.cli.serialization.userfacing.input.GcsBucketLifecycle)1 GcsStorageClass (bio.terra.cli.serialization.userfacing.input.GcsStorageClass)1 CreateControlledGcpGcsBucketRequestBody (bio.terra.workspace.model.CreateControlledGcpGcsBucketRequestBody)1 GcpGcsBucketCreationParameters (bio.terra.workspace.model.GcpGcsBucketCreationParameters)1 GcpGcsBucketLifecycleRuleAction (bio.terra.workspace.model.GcpGcsBucketLifecycleRuleAction)1 GcpGcsBucketLifecycleRuleCondition (bio.terra.workspace.model.GcpGcsBucketLifecycleRuleCondition)1 GcpGcsBucketUpdateParameters (bio.terra.workspace.model.GcpGcsBucketUpdateParameters)1 UpdateControlledGcpGcsBucketRequestBody (bio.terra.workspace.model.UpdateControlledGcpGcsBucketRequestBody)1 ArrayList (java.util.ArrayList)1