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);
}
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);
}
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;
}
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));
}
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());
}
Aggregations