Search in sources :

Example 1 with ControlledAzureRelayNamespaceResource

use of bio.terra.workspace.service.resource.controlled.cloud.azure.relayNamespace.ControlledAzureRelayNamespaceResource in project terra-workspace-manager by DataBiosphere.

the class ControlledAzureResourceApiController method createAzureRelayNamespace.

@Override
public ResponseEntity<ApiCreateControlledAzureRelayNamespace> createAzureRelayNamespace(UUID workspaceId, @Valid ApiCreateControlledAzureRelayNamespaceRequestBody body) {
    features.azureEnabledCheck();
    final AuthenticatedUserRequest userRequest = getAuthenticatedInfo();
    ControlledResourceFields commonFields = toCommonFields(workspaceId, body.getCommon(), userRequest);
    ControlledAzureRelayNamespaceResource resource = ControlledAzureRelayNamespaceResource.builder().common(commonFields).namespaceName(body.getAzureRelayNamespace().getNamespaceName()).region(body.getAzureRelayNamespace().getRegion()).build();
    final ControlledAzureRelayNamespaceResource created = controlledResourceService.createControlledResourceSync(resource, commonFields.getIamRole(), userRequest, body.getAzureRelayNamespace()).castByEnum(WsmResourceType.CONTROLLED_AZURE_RELAY_NAMESPACE);
    var response = new ApiCreateControlledAzureRelayNamespace().resourceId(created.getResourceId()).azureRelayNameSpace(created.toApiResource());
    return new ResponseEntity<>(response, HttpStatus.OK);
}
Also used : ApiCreateControlledAzureRelayNamespace(bio.terra.workspace.generated.model.ApiCreateControlledAzureRelayNamespace) ResponseEntity(org.springframework.http.ResponseEntity) AuthenticatedUserRequest(bio.terra.workspace.service.iam.AuthenticatedUserRequest) ControlledResourceFields(bio.terra.workspace.service.resource.controlled.model.ControlledResourceFields) ControlledAzureRelayNamespaceResource(bio.terra.workspace.service.resource.controlled.cloud.azure.relayNamespace.ControlledAzureRelayNamespaceResource)

Example 2 with ControlledAzureRelayNamespaceResource

use of bio.terra.workspace.service.resource.controlled.cloud.azure.relayNamespace.ControlledAzureRelayNamespaceResource in project terra-workspace-manager by DataBiosphere.

the class CreateAndDeleteAzureControlledResourceFlightTest method createAndDeleteAzureRelayNamespaceControlledResource.

@Test
public void createAndDeleteAzureRelayNamespaceControlledResource() throws InterruptedException {
    UUID workspaceId = azureTestUtils.createWorkspace(workspaceService);
    AuthenticatedUserRequest userRequest = userAccessUtils.defaultUserAuthRequest();
    // Cloud context needs to be created first
    FlightState createAzureContextFlightState = StairwayTestUtils.blockUntilFlightCompletes(jobService.getStairway(), CreateAzureContextFlight.class, azureTestUtils.createAzureContextInputParameters(workspaceId, userRequest), STAIRWAY_FLIGHT_TIMEOUT, null);
    assertEquals(FlightStatus.SUCCESS, createAzureContextFlightState.getFlightStatus());
    assertTrue(workspaceService.getAuthorizedAzureCloudContext(workspaceId, userRequest).isPresent());
    final ApiAzureRelayNamespaceCreationParameters creationParameters = ControlledResourceFixtures.getAzureRelayNamespaceCreationParameters();
    final UUID resourceId = UUID.randomUUID();
    ControlledAzureRelayNamespaceResource resource = ControlledAzureRelayNamespaceResource.builder().common(ControlledResourceFields.builder().workspaceId(workspaceId).resourceId(resourceId).name(getAzureName("ip")).description(getAzureName("ip-desc")).cloningInstructions(CloningInstructions.COPY_RESOURCE).accessScope(AccessScopeType.fromApi(ApiAccessScope.SHARED_ACCESS)).managedBy(ManagedByType.fromApi(ApiManagedBy.USER)).build()).namespaceName(creationParameters.getNamespaceName()).region(creationParameters.getRegion()).build();
    // Submit an IP creation flight.
    FlightState flightState = StairwayTestUtils.blockUntilFlightCompletes(jobService.getStairway(), CreateControlledResourceFlight.class, azureTestUtils.createControlledResourceInputParameters(workspaceId, userRequest, resource), STAIRWAY_FLIGHT_TIMEOUT, null);
    assertEquals(FlightStatus.SUCCESS, flightState.getFlightStatus());
    // Verify controlled resource exists in the workspace.
    ControlledResource res = controlledResourceService.getControlledResource(workspaceId, resourceId, userRequest);
    var relayNamespaceResource = res.castByEnum(WsmResourceType.CONTROLLED_AZURE_RELAY_NAMESPACE);
    assertEquals(resource, relayNamespaceResource);
    // Submit a VM deletion flight.
    FlightState deleteFlightState = StairwayTestUtils.blockUntilFlightCompletes(jobService.getStairway(), DeleteControlledResourceFlight.class, azureTestUtils.deleteControlledResourceInputParameters(workspaceId, resourceId, userRequest, resource), STAIRWAY_FLIGHT_TIMEOUT, null);
    assertEquals(FlightStatus.SUCCESS, deleteFlightState.getFlightStatus());
    TimeUnit.SECONDS.sleep(5);
    RelayManager manager = azureTestUtils.getRelayManager();
    ManagementException exception = assertThrows(ManagementException.class, () -> manager.namespaces().getByResourceGroup(azureTestUtils.getAzureCloudContext().getAzureResourceGroupId(), resource.getNamespaceName()));
    // We see both ResourceNotFound and NotFound in the code field
    assertTrue(exception.getValue().getCode().contains("NotFound"));
}
Also used : FlightState(bio.terra.stairway.FlightState) ApiAzureRelayNamespaceCreationParameters(bio.terra.workspace.generated.model.ApiAzureRelayNamespaceCreationParameters) ManagementException(com.azure.core.management.exception.ManagementException) ControlledResource(bio.terra.workspace.service.resource.controlled.model.ControlledResource) RelayManager(com.azure.resourcemanager.relay.RelayManager) AuthenticatedUserRequest(bio.terra.workspace.service.iam.AuthenticatedUserRequest) UUID(java.util.UUID) ControlledAzureRelayNamespaceResource(bio.terra.workspace.service.resource.controlled.cloud.azure.relayNamespace.ControlledAzureRelayNamespaceResource) Test(org.junit.jupiter.api.Test) BaseAzureTest(bio.terra.workspace.common.BaseAzureTest)

Aggregations

AuthenticatedUserRequest (bio.terra.workspace.service.iam.AuthenticatedUserRequest)2 ControlledAzureRelayNamespaceResource (bio.terra.workspace.service.resource.controlled.cloud.azure.relayNamespace.ControlledAzureRelayNamespaceResource)2 FlightState (bio.terra.stairway.FlightState)1 BaseAzureTest (bio.terra.workspace.common.BaseAzureTest)1 ApiAzureRelayNamespaceCreationParameters (bio.terra.workspace.generated.model.ApiAzureRelayNamespaceCreationParameters)1 ApiCreateControlledAzureRelayNamespace (bio.terra.workspace.generated.model.ApiCreateControlledAzureRelayNamespace)1 ControlledResource (bio.terra.workspace.service.resource.controlled.model.ControlledResource)1 ControlledResourceFields (bio.terra.workspace.service.resource.controlled.model.ControlledResourceFields)1 ManagementException (com.azure.core.management.exception.ManagementException)1 RelayManager (com.azure.resourcemanager.relay.RelayManager)1 UUID (java.util.UUID)1 Test (org.junit.jupiter.api.Test)1 ResponseEntity (org.springframework.http.ResponseEntity)1