Search in sources :

Example 11 with ControlledResourceFields

use of bio.terra.workspace.service.resource.controlled.model.ControlledResourceFields in project terra-workspace-manager by DataBiosphere.

the class ControlledAzureResourceApiController method createAzureStorage.

@Override
public ResponseEntity<ApiCreatedControlledAzureStorage> createAzureStorage(UUID workspaceId, @Valid ApiCreateControlledAzureStorageRequestBody body) {
    features.azureEnabledCheck();
    final AuthenticatedUserRequest userRequest = getAuthenticatedInfo();
    final ControlledResourceFields commonFields = toCommonFields(workspaceId, body.getCommon(), userRequest);
    ControlledAzureStorageResource resource = ControlledAzureStorageResource.builder().common(commonFields).storageAccountName(body.getAzureStorage().getName()).region(body.getAzureStorage().getRegion()).build();
    final ControlledAzureStorageResource createdStorage = controlledResourceService.createControlledResourceSync(resource, commonFields.getIamRole(), userRequest, body.getAzureStorage()).castByEnum(WsmResourceType.CONTROLLED_AZURE_STORAGE_ACCOUNT);
    var response = new ApiCreatedControlledAzureStorage().resourceId(createdStorage.getResourceId()).azureStorage(createdStorage.toApiResource());
    return new ResponseEntity<>(response, HttpStatus.OK);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) ControlledAzureStorageResource(bio.terra.workspace.service.resource.controlled.cloud.azure.storage.ControlledAzureStorageResource) AuthenticatedUserRequest(bio.terra.workspace.service.iam.AuthenticatedUserRequest) ControlledResourceFields(bio.terra.workspace.service.resource.controlled.model.ControlledResourceFields) ApiCreatedControlledAzureStorage(bio.terra.workspace.generated.model.ApiCreatedControlledAzureStorage)

Example 12 with ControlledResourceFields

use of bio.terra.workspace.service.resource.controlled.model.ControlledResourceFields in project terra-workspace-manager by DataBiosphere.

the class ControlledAzureResourceApiController method createAzureNetwork.

@Override
public ResponseEntity<ApiCreatedControlledAzureNetwork> createAzureNetwork(UUID workspaceId, ApiCreateControlledAzureNetworkRequestBody body) {
    features.azureEnabledCheck();
    final AuthenticatedUserRequest userRequest = getAuthenticatedInfo();
    final ControlledResourceFields commonFields = toCommonFields(workspaceId, body.getCommon(), userRequest);
    ControlledAzureNetworkResource resource = ControlledAzureNetworkResource.builder().common(commonFields).networkName(body.getAzureNetwork().getName()).subnetName(body.getAzureNetwork().getSubnetName()).addressSpaceCidr(body.getAzureNetwork().getAddressSpaceCidr()).subnetAddressCidr(body.getAzureNetwork().getSubnetAddressCidr()).region(body.getAzureNetwork().getRegion()).build();
    final ControlledAzureNetworkResource createdNetwork = controlledResourceService.createControlledResourceSync(resource, commonFields.getIamRole(), userRequest, body.getAzureNetwork()).castByEnum(WsmResourceType.CONTROLLED_AZURE_NETWORK);
    var response = new ApiCreatedControlledAzureNetwork().resourceId(createdNetwork.getResourceId()).azureNetwork(createdNetwork.toApiResource());
    return new ResponseEntity<>(response, HttpStatus.OK);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) AuthenticatedUserRequest(bio.terra.workspace.service.iam.AuthenticatedUserRequest) ControlledResourceFields(bio.terra.workspace.service.resource.controlled.model.ControlledResourceFields) ApiCreatedControlledAzureNetwork(bio.terra.workspace.generated.model.ApiCreatedControlledAzureNetwork) ControlledAzureNetworkResource(bio.terra.workspace.service.resource.controlled.cloud.azure.network.ControlledAzureNetworkResource)

Example 13 with ControlledResourceFields

use of bio.terra.workspace.service.resource.controlled.model.ControlledResourceFields in project terra-workspace-manager by DataBiosphere.

the class ControlledAiNotebookHandler method makeResourceFromDb.

/**
 * {@inheritDoc}
 */
@Override
public WsmResource makeResourceFromDb(DbResource dbResource) {
    // Old version of attributes do not have project id, so in that case we look it up
    ControlledAiNotebookInstanceAttributes attributes = DbSerDes.fromJson(dbResource.getAttributes(), ControlledAiNotebookInstanceAttributes.class);
    String projectId = Optional.ofNullable(attributes.getProjectId()).orElse(gcpCloudContextService.getRequiredGcpProject(dbResource.getWorkspaceId()));
    var resource = ControlledAiNotebookInstanceResource.builder().common(new ControlledResourceFields(dbResource)).instanceId(attributes.getInstanceId()).location(attributes.getLocation()).projectId(projectId).build();
    return resource;
}
Also used : ControlledResourceFields(bio.terra.workspace.service.resource.controlled.model.ControlledResourceFields)

Example 14 with ControlledResourceFields

use of bio.terra.workspace.service.resource.controlled.model.ControlledResourceFields in project terra-workspace-manager by DataBiosphere.

the class AzureDisabledTest method azureDisabledTest.

@Test
public void azureDisabledTest() throws InterruptedException {
    Workspace request = Workspace.builder().workspaceId(UUID.randomUUID()).workspaceStage(WorkspaceStage.MC_WORKSPACE).build();
    UUID workspaceId = workspaceService.createWorkspace(request, userAccessUtils.defaultUserAuthRequest());
    AuthenticatedUserRequest userRequest = userAccessUtils.defaultUserAuthRequest();
    final UUID uuid = UUID.randomUUID();
    assertThrows(FeatureNotSupportedException.class, () -> workspaceService.createAzureCloudContext(workspaceId, uuid.toString(), userRequest, null, null));
    assertThrows(FeatureNotSupportedException.class, () -> workspaceService.getAuthorizedAzureCloudContext(workspaceId, userRequest));
    final ApiAzureIpCreationParameters ipCreationParameters = ControlledResourceFixtures.getAzureIpCreationParameters();
    ControlledResourceFields commonFields = ControlledResourceFixtures.makeDefaultControlledResourceFields(workspaceId);
    ControlledAzureIpResource ipResource = ControlledAzureIpResource.builder().common(commonFields).ipName(ipCreationParameters.getName()).region(ipCreationParameters.getRegion()).build();
    assertThrows(FeatureNotSupportedException.class, () -> controlledResourceService.createControlledResourceSync(ipResource, null, userRequest, ipCreationParameters));
    final ApiAzureDiskCreationParameters diskCreationParameters = ControlledResourceFixtures.getAzureDiskCreationParameters();
    ControlledAzureDiskResource diskResource = ControlledAzureDiskResource.builder().common(commonFields).diskName(diskCreationParameters.getName()).region(diskCreationParameters.getRegion()).size(diskCreationParameters.getSize()).build();
    assertThrows(FeatureNotSupportedException.class, () -> controlledResourceService.createControlledResourceSync(diskResource, null, userRequest, diskCreationParameters));
    final ApiAzureNetworkCreationParameters networkCreationParameters = ControlledResourceFixtures.getAzureNetworkCreationParameters();
    ControlledAzureNetworkResource networkResource = ControlledAzureNetworkResource.builder().common(commonFields).networkName(networkCreationParameters.getName()).region(networkCreationParameters.getRegion()).subnetName(networkCreationParameters.getSubnetName()).addressSpaceCidr(networkCreationParameters.getAddressSpaceCidr()).subnetAddressCidr(networkCreationParameters.getSubnetAddressCidr()).build();
    assertThrows(FeatureNotSupportedException.class, () -> controlledResourceService.createControlledResourceSync(networkResource, null, userRequest, networkCreationParameters));
    final ApiAzureVmCreationParameters vmCreationParameters = ControlledResourceFixtures.getAzureVmCreationParameters();
    ControlledAzureVmResource vmResource = ControlledAzureVmResource.builder().common(commonFields).vmName(vmCreationParameters.getName()).vmSize(vmCreationParameters.getVmSize()).vmImageUri(vmCreationParameters.getVmImageUri()).region(vmCreationParameters.getRegion()).ipId(ipResource.getResourceId()).diskId(diskResource.getResourceId()).networkId(networkResource.getResourceId()).build();
    assertThrows(FeatureNotSupportedException.class, () -> controlledResourceService.createAzureVm(vmResource, vmCreationParameters, null, null, null, userRequest));
}
Also used : ApiAzureIpCreationParameters(bio.terra.workspace.generated.model.ApiAzureIpCreationParameters) ControlledAzureIpResource(bio.terra.workspace.service.resource.controlled.cloud.azure.ip.ControlledAzureIpResource) ControlledAzureVmResource(bio.terra.workspace.service.resource.controlled.cloud.azure.vm.ControlledAzureVmResource) ControlledAzureDiskResource(bio.terra.workspace.service.resource.controlled.cloud.azure.disk.ControlledAzureDiskResource) AuthenticatedUserRequest(bio.terra.workspace.service.iam.AuthenticatedUserRequest) ApiAzureVmCreationParameters(bio.terra.workspace.generated.model.ApiAzureVmCreationParameters) UUID(java.util.UUID) ControlledResourceFields(bio.terra.workspace.service.resource.controlled.model.ControlledResourceFields) ApiAzureNetworkCreationParameters(bio.terra.workspace.generated.model.ApiAzureNetworkCreationParameters) ApiAzureDiskCreationParameters(bio.terra.workspace.generated.model.ApiAzureDiskCreationParameters) ControlledAzureNetworkResource(bio.terra.workspace.service.resource.controlled.cloud.azure.network.ControlledAzureNetworkResource) Workspace(bio.terra.workspace.service.workspace.model.Workspace) BaseConnectedTest(bio.terra.workspace.common.BaseConnectedTest) Test(org.junit.jupiter.api.Test)

Example 15 with ControlledResourceFields

use of bio.terra.workspace.service.resource.controlled.model.ControlledResourceFields in project terra-workspace-manager by DataBiosphere.

the class ControlledAiNotebookInstanceResourceTest method validateSharedAccessThrows.

@Test
public void validateSharedAccessThrows() {
    ControlledResourceFields commonFields = ControlledResourceFixtures.makeNotebookCommonFieldsBuilder().accessScope(AccessScopeType.ACCESS_SCOPE_SHARED).build();
    assertThrows(BadRequestException.class, () -> ControlledAiNotebookInstanceResource.builder().common(commonFields).instanceId("an-instance").location("us-east1-b").projectId("a-projecct-id").build());
}
Also used : ControlledResourceFields(bio.terra.workspace.service.resource.controlled.model.ControlledResourceFields) Test(org.junit.jupiter.api.Test) BaseUnitTest(bio.terra.workspace.common.BaseUnitTest)

Aggregations

ControlledResourceFields (bio.terra.workspace.service.resource.controlled.model.ControlledResourceFields)21 AuthenticatedUserRequest (bio.terra.workspace.service.iam.AuthenticatedUserRequest)11 ResponseEntity (org.springframework.http.ResponseEntity)9 Test (org.junit.jupiter.api.Test)7 UUID (java.util.UUID)6 BaseConnectedTest (bio.terra.workspace.common.BaseConnectedTest)4 ControlledGcsBucketResource (bio.terra.workspace.service.resource.controlled.cloud.gcp.gcsbucket.ControlledGcsBucketResource)4 ControlledResource (bio.terra.workspace.service.resource.controlled.model.ControlledResource)4 BaseUnitTest (bio.terra.workspace.common.BaseUnitTest)3 ApiGcpGcsBucketCreationParameters (bio.terra.workspace.generated.model.ApiGcpGcsBucketCreationParameters)3 ControlledAiNotebookInstanceResource (bio.terra.workspace.service.resource.controlled.cloud.gcp.ainotebook.ControlledAiNotebookInstanceResource)3 ControlledBigQueryDatasetResource (bio.terra.workspace.service.resource.controlled.cloud.gcp.bqdataset.ControlledBigQueryDatasetResource)3 FlightMap (bio.terra.stairway.FlightMap)2 ApiCreatedControlledGcpGcsBucket (bio.terra.workspace.generated.model.ApiCreatedControlledGcpGcsBucket)2 ApiGcpBigQueryDatasetCreationParameters (bio.terra.workspace.generated.model.ApiGcpBigQueryDatasetCreationParameters)2 ControlledResourceIamRole (bio.terra.workspace.service.iam.model.ControlledResourceIamRole)2 ControlledAzureDiskResource (bio.terra.workspace.service.resource.controlled.cloud.azure.disk.ControlledAzureDiskResource)2 ControlledAzureIpResource (bio.terra.workspace.service.resource.controlled.cloud.azure.ip.ControlledAzureIpResource)2 ControlledAzureNetworkResource (bio.terra.workspace.service.resource.controlled.cloud.azure.network.ControlledAzureNetworkResource)2 ControlledAzureVmResource (bio.terra.workspace.service.resource.controlled.cloud.azure.vm.ControlledAzureVmResource)2