Search in sources :

Example 6 with ApiClient

use of bio.terra.workspace.client.ApiClient in project terra-workspace-manager by DataBiosphere.

the class ClientTestUtils method buildClient.

private static ApiClient buildClient(@Nullable AccessToken accessToken, ServerSpecification server) throws IOException {
    if (Strings.isNullOrEmpty(server.workspaceManagerUri)) {
        throw new IllegalArgumentException("Workspace Manager Service URI cannot be empty");
    }
    // build the client object
    ApiClient apiClient = new ApiClient();
    apiClient.setBasePath(server.workspaceManagerUri);
    if (accessToken != null) {
        apiClient.setAccessToken(accessToken.getTokenValue());
    }
    return apiClient;
}
Also used : ApiClient(bio.terra.workspace.client.ApiClient)

Example 7 with ApiClient

use of bio.terra.workspace.client.ApiClient in project terra-cli by DataBiosphere.

the class WorkspaceManagerService method cloneWorkspace.

/**
 * Call the Workspace Manager POST "/api/workspaces/v1/{workspaceId}/clone" endpoint to clone a
 * workspace.
 *
 * @param workspaceId - workspace ID to clone
 * @param userFacingId - required userFacingId of new cloned workspace
 * @param name - optional name of new cloned workspace
 * @param description - optional description for new workspace
 * @return object with information about the clone job success and destination workspace
 */
public CloneWorkspaceResult cloneWorkspace(UUID workspaceId, String userFacingId, @Nullable String name, @Nullable String description) {
    var request = new CloneWorkspaceRequest().spendProfile(Context.getServer().getWsmDefaultSpendProfile()).userFacingId(userFacingId).displayName(name).description(description).location(null);
    WorkspaceApi workspaceApi = new WorkspaceApi(apiClient);
    CloneWorkspaceResult initialResult = callWithRetries(() -> workspaceApi.cloneWorkspace(request, workspaceId), "Error cloning workspace");
    logger.debug("clone workspace initial result: {}", initialResult);
    // poll until the workspace clone completes.
    // TODO PF-745: return immediately and give some interface for checking on the job status
    // and retrieving the result.
    CloneWorkspaceResult cloneWorkspaceResult = handleClientExceptions(() -> HttpUtils.pollWithRetries(() -> workspaceApi.getCloneWorkspaceResult(workspaceId, initialResult.getJobReport().getId()), (result) -> isDone(result.getJobReport()), WorkspaceManagerService::isRetryable, CLONE_WORKSPACE_MAXIMUM_RETRIES, CLONE_WORKSPACE_RETRY_INTERVAL), "Error in cloning workspace.");
    logger.debug("clone workspace polling result: {}", cloneWorkspaceResult);
    throwIfJobNotCompleted(cloneWorkspaceResult.getJobReport(), cloneWorkspaceResult.getErrorReport());
    return cloneWorkspaceResult;
}
Also used : Context(bio.terra.cli.businessobject.Context) JobControl(bio.terra.workspace.model.JobControl) GcpGcsBucketAttributes(bio.terra.workspace.model.GcpGcsBucketAttributes) StatusEnum(bio.terra.workspace.model.JobReport.StatusEnum) WorkspaceDescriptionList(bio.terra.workspace.model.WorkspaceDescriptionList) ErrorReport(bio.terra.workspace.model.ErrorReport) GcpBigQueryDataTableAttributes(bio.terra.workspace.model.GcpBigQueryDataTableAttributes) Duration(java.time.Duration) ZoneOffset(java.time.ZoneOffset) UpdateReferencedBqDatasetParams(bio.terra.cli.serialization.userfacing.input.UpdateReferencedBqDatasetParams) GcpAiNotebookInstanceVmImage(bio.terra.workspace.model.GcpAiNotebookInstanceVmImage) GcpAiNotebookInstanceAcceleratorConfig(bio.terra.workspace.model.GcpAiNotebookInstanceAcceleratorConfig) CreateGcsBucketParams(bio.terra.cli.serialization.userfacing.input.CreateGcsBucketParams) ControlledResourceCommonFields(bio.terra.workspace.model.ControlledResourceCommonFields) UpdateControlledGcpBigQueryDatasetRequestBody(bio.terra.workspace.model.UpdateControlledGcpBigQueryDatasetRequestBody) ApiClient(bio.terra.workspace.client.ApiClient) GcpGcsBucketLifecycleRuleAction(bio.terra.workspace.model.GcpGcsBucketLifecycleRuleAction) UpdateGcsBucketObjectReferenceRequestBody(bio.terra.workspace.model.UpdateGcsBucketObjectReferenceRequestBody) CreatedControlledGcpAiNotebookInstanceResult(bio.terra.workspace.model.CreatedControlledGcpAiNotebookInstanceResult) GitRepoResource(bio.terra.workspace.model.GitRepoResource) IamRole(bio.terra.workspace.model.IamRole) UpdateBigQueryDatasetReferenceRequestBody(bio.terra.workspace.model.UpdateBigQueryDatasetReferenceRequestBody) GcsBucketLifecycle(bio.terra.cli.serialization.userfacing.input.GcsBucketLifecycle) GcsStorageClass(bio.terra.cli.serialization.userfacing.input.GcsStorageClass) UpdateReferencedBqTableParams(bio.terra.cli.serialization.userfacing.input.UpdateReferencedBqTableParams) GcpBigQueryDatasetCreationParameters(bio.terra.workspace.model.GcpBigQueryDatasetCreationParameters) HttpStatusCodes(com.google.api.client.http.HttpStatusCodes) CreateGcpGcsBucketReferenceRequestBody(bio.terra.workspace.model.CreateGcpGcsBucketReferenceRequestBody) GcpGcsBucketResource(bio.terra.workspace.model.GcpGcsBucketResource) AddBqTableParams(bio.terra.cli.serialization.userfacing.input.AddBqTableParams) ReferenceResourceCommonFields(bio.terra.workspace.model.ReferenceResourceCommonFields) UpdateBigQueryDataTableReferenceRequestBody(bio.terra.workspace.model.UpdateBigQueryDataTableReferenceRequestBody) CreateControlledGcpAiNotebookInstanceRequestBody(bio.terra.workspace.model.CreateControlledGcpAiNotebookInstanceRequestBody) GcpBigQueryDataTableResource(bio.terra.workspace.model.GcpBigQueryDataTableResource) UpdateWorkspaceRequestBody(bio.terra.workspace.model.UpdateWorkspaceRequestBody) DeleteControlledGcpGcsBucketRequest(bio.terra.workspace.model.DeleteControlledGcpGcsBucketRequest) ArrayList(java.util.ArrayList) CreateWorkspaceRequestBody(bio.terra.workspace.model.CreateWorkspaceRequestBody) GcpAiNotebookInstanceContainerImage(bio.terra.workspace.model.GcpAiNotebookInstanceContainerImage) GcpGcsBucketCreationParameters(bio.terra.workspace.model.GcpGcsBucketCreationParameters) GcpGcsObjectAttributes(bio.terra.workspace.model.GcpGcsObjectAttributes) WorkspaceApi(bio.terra.workspace.api.WorkspaceApi) WorkspaceStageModel(bio.terra.workspace.model.WorkspaceStageModel) Nullable(javax.annotation.Nullable) DeleteControlledGcpAiNotebookInstanceRequest(bio.terra.workspace.model.DeleteControlledGcpAiNotebookInstanceRequest) CreateControlledGcpGcsBucketRequestBody(bio.terra.workspace.model.CreateControlledGcpGcsBucketRequestBody) ApiException(bio.terra.workspace.client.ApiException) CloneWorkspaceResult(bio.terra.workspace.model.CloneWorkspaceResult) GcpGcsObjectResource(bio.terra.workspace.model.GcpGcsObjectResource) DeleteControlledGcpGcsBucketResult(bio.terra.workspace.model.DeleteControlledGcpGcsBucketResult) GcpAiNotebookInstanceCreationParameters(bio.terra.workspace.model.GcpAiNotebookInstanceCreationParameters) GrantRoleRequestBody(bio.terra.workspace.model.GrantRoleRequestBody) ResourceApi(bio.terra.workspace.api.ResourceApi) CreateGcpNotebookParams(bio.terra.cli.serialization.userfacing.input.CreateGcpNotebookParams) GcpBigQueryDatasetAttributes(bio.terra.workspace.model.GcpBigQueryDatasetAttributes) AccessScope(bio.terra.workspace.model.AccessScope) UpdateGitRepoReferenceRequestBody(bio.terra.workspace.model.UpdateGitRepoReferenceRequestBody) ControlledGcpResourceApi(bio.terra.workspace.api.ControlledGcpResourceApi) GcpGcsBucketLifecycleRule(bio.terra.workspace.model.GcpGcsBucketLifecycleRule) LoggerFactory(org.slf4j.LoggerFactory) WorkspaceDescription(bio.terra.workspace.model.WorkspaceDescription) HttpStatus(org.apache.http.HttpStatus) ControlledResourceIamRole(bio.terra.workspace.model.ControlledResourceIamRole) UpdateControlledBqDatasetParams(bio.terra.cli.serialization.userfacing.input.UpdateControlledBqDatasetParams) CreateCloudContextResult(bio.terra.workspace.model.CreateCloudContextResult) GcpBigQueryDatasetResource(bio.terra.workspace.model.GcpBigQueryDatasetResource) GcpGcsBucketLifecycle(bio.terra.workspace.model.GcpGcsBucketLifecycle) UpdateReferencedGcsObjectParams(bio.terra.cli.serialization.userfacing.input.UpdateReferencedGcsObjectParams) DeleteControlledGcpAiNotebookInstanceResult(bio.terra.workspace.model.DeleteControlledGcpAiNotebookInstanceResult) LocalTime(java.time.LocalTime) GcpGcsBucketLifecycleRuleCondition(bio.terra.workspace.model.GcpGcsBucketLifecycleRuleCondition) AddGcsObjectParams(bio.terra.cli.serialization.userfacing.input.AddGcsObjectParams) Predicate(java.util.function.Predicate) UpdateControlledGcpGcsBucketRequestBody(bio.terra.workspace.model.UpdateControlledGcpGcsBucketRequestBody) GcpBigQueryDatasetUpdateParameters(bio.terra.workspace.model.GcpBigQueryDatasetUpdateParameters) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) PrivateResourceUser(bio.terra.workspace.model.PrivateResourceUser) CreateCloudContextRequest(bio.terra.workspace.model.CreateCloudContextRequest) AddGitRepoParams(bio.terra.cli.serialization.userfacing.input.AddGitRepoParams) List(java.util.List) OffsetDateTime(java.time.OffsetDateTime) LocalDate(java.time.LocalDate) UpdateReferencedGitRepoParams(bio.terra.cli.serialization.userfacing.input.UpdateReferencedGitRepoParams) SystemException(bio.terra.cli.exception.SystemException) CreateGcpBigQueryDataTableReferenceRequestBody(bio.terra.workspace.model.CreateGcpBigQueryDataTableReferenceRequestBody) GcpAiNotebookInstanceResource(bio.terra.workspace.model.GcpAiNotebookInstanceResource) UpdateControlledGcsBucketParams(bio.terra.cli.serialization.userfacing.input.UpdateControlledGcsBucketParams) RoleBindingList(bio.terra.workspace.model.RoleBindingList) ManagedBy(bio.terra.workspace.model.ManagedBy) PrivateResourceIamRoles(bio.terra.workspace.model.PrivateResourceIamRoles) ResourceList(bio.terra.workspace.model.ResourceList) JacksonMapper(bio.terra.cli.utils.JacksonMapper) CreateControlledGcpBigQueryDatasetRequestBody(bio.terra.workspace.model.CreateControlledGcpBigQueryDatasetRequestBody) GcpGcsBucketUpdateParameters(bio.terra.workspace.model.GcpGcsBucketUpdateParameters) HttpUtils(bio.terra.cli.service.utils.HttpUtils) JobReport(bio.terra.workspace.model.JobReport) CreateGcpGcsObjectReferenceRequestBody(bio.terra.workspace.model.CreateGcpGcsObjectReferenceRequestBody) CreateGcpBigQueryDatasetReferenceRequestBody(bio.terra.workspace.model.CreateGcpBigQueryDatasetReferenceRequestBody) ReferencedGcpResourceApi(bio.terra.workspace.api.ReferencedGcpResourceApi) UpdateGcsBucketReferenceRequestBody(bio.terra.workspace.model.UpdateGcsBucketReferenceRequestBody) UpdateReferencedGcsBucketParams(bio.terra.cli.serialization.userfacing.input.UpdateReferencedGcsBucketParams) CloudPlatform(bio.terra.workspace.model.CloudPlatform) Logger(org.slf4j.Logger) UserActionableException(bio.terra.cli.exception.UserActionableException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) UnauthenticatedApi(bio.terra.workspace.api.UnauthenticatedApi) CreateBqDatasetParams(bio.terra.cli.serialization.userfacing.input.CreateBqDatasetParams) Server(bio.terra.cli.businessobject.Server) CreateGitRepoReferenceRequestBody(bio.terra.workspace.model.CreateGitRepoReferenceRequestBody) SystemVersion(bio.terra.workspace.model.SystemVersion) ResourceDescription(bio.terra.workspace.model.ResourceDescription) CreateResourceParams(bio.terra.cli.serialization.userfacing.input.CreateResourceParams) CloneWorkspaceRequest(bio.terra.workspace.model.CloneWorkspaceRequest) GitRepoAttributes(bio.terra.workspace.model.GitRepoAttributes) AccessToken(com.google.auth.oauth2.AccessToken) CloneWorkspaceResult(bio.terra.workspace.model.CloneWorkspaceResult) CloneWorkspaceRequest(bio.terra.workspace.model.CloneWorkspaceRequest) WorkspaceApi(bio.terra.workspace.api.WorkspaceApi)

Aggregations

ApiClient (bio.terra.workspace.client.ApiClient)7 ControlledGcpResourceApi (bio.terra.workspace.api.ControlledGcpResourceApi)5 ResourceApi (bio.terra.workspace.api.ResourceApi)4 ReferencedGcpResourceApi (bio.terra.workspace.api.ReferencedGcpResourceApi)3 TestUserSpecification (bio.terra.testrunner.runner.config.TestUserSpecification)2 UnauthenticatedApi (bio.terra.workspace.api.UnauthenticatedApi)2 WorkspaceApplicationApi (bio.terra.workspace.api.WorkspaceApplicationApi)2 ApiException (bio.terra.workspace.client.ApiException)2 GrantRoleRequestBody (bio.terra.workspace.model.GrantRoleRequestBody)2 ResourceList (bio.terra.workspace.model.ResourceList)2 WorkspaceApplicationDescription (bio.terra.workspace.model.WorkspaceApplicationDescription)2 Context (bio.terra.cli.businessobject.Context)1 Server (bio.terra.cli.businessobject.Server)1 SystemException (bio.terra.cli.exception.SystemException)1 UserActionableException (bio.terra.cli.exception.UserActionableException)1 AddBqTableParams (bio.terra.cli.serialization.userfacing.input.AddBqTableParams)1 AddGcsObjectParams (bio.terra.cli.serialization.userfacing.input.AddGcsObjectParams)1 AddGitRepoParams (bio.terra.cli.serialization.userfacing.input.AddGitRepoParams)1 CreateBqDatasetParams (bio.terra.cli.serialization.userfacing.input.CreateBqDatasetParams)1 CreateGcpNotebookParams (bio.terra.cli.serialization.userfacing.input.CreateGcpNotebookParams)1