Search in sources :

Example 1 with ApiAzureRelayNamespaceCreationParameters

use of bio.terra.workspace.generated.model.ApiAzureRelayNamespaceCreationParameters in project terra-workspace-manager by DataBiosphere.

the class CreateAzureRelayNamespaceStepTest method createRelayNamespace.

@Test
void createRelayNamespace() throws InterruptedException {
    final ApiAzureRelayNamespaceCreationParameters creationParameters = ControlledResourceFixtures.getAzureRelayNamespaceCreationParameters();
    CreateAzureRelayNamespaceStep createAzureIpStep = new CreateAzureRelayNamespaceStep(mockAzureConfig, mockCrlService, ControlledResourceFixtures.getAzureRelayNamespace(creationParameters.getNamespaceName(), creationParameters.getRegion()));
    final StepResult stepResult = createAzureIpStep.doStep(mockFlightContext);
    // Verify step returns success
    assertThat(stepResult, equalTo(StepResult.getStepResultSuccess()));
    // Verify Azure create call was made correctly
    verify(mockStage3).create(contextCaptor.capture());
    Context context = contextCaptor.getValue();
    Optional<CreateRelayRequestData> requestDataOpt = context.getValues().values().stream().filter(CreateRelayRequestData.class::isInstance).map(CreateRelayRequestData.class::cast).findFirst();
    CreateRelayRequestData expected = CreateRelayRequestData.builder().setName(creationParameters.getNamespaceName()).setRegion(Region.fromName(creationParameters.getRegion())).setTenantId(dummyAzureCloudContext.getAzureTenantId()).setSubscriptionId(dummyAzureCloudContext.getAzureSubscriptionId()).setResourceGroupName(dummyAzureCloudContext.getAzureResourceGroupId()).build();
    assertThat(requestDataOpt, equalTo(Optional.of(expected)));
}
Also used : Context(com.azure.core.util.Context) AzureCloudContext(bio.terra.workspace.service.workspace.model.AzureCloudContext) FlightContext(bio.terra.stairway.FlightContext) ApiAzureRelayNamespaceCreationParameters(bio.terra.workspace.generated.model.ApiAzureRelayNamespaceCreationParameters) StepResult(bio.terra.stairway.StepResult) CreateRelayRequestData(bio.terra.cloudres.azure.resourcemanager.relay.data.CreateRelayRequestData) Test(org.junit.jupiter.api.Test) BaseAzureTest(bio.terra.workspace.common.BaseAzureTest)

Example 2 with ApiAzureRelayNamespaceCreationParameters

use of bio.terra.workspace.generated.model.ApiAzureRelayNamespaceCreationParameters in project terra-workspace-manager by DataBiosphere.

the class GetAzureRelayNamespaceStepTest method getRelayNamespace_alreadyExists.

@Test
public void getRelayNamespace_alreadyExists() throws InterruptedException {
    final ApiAzureRelayNamespaceCreationParameters creationParameters = ControlledResourceFixtures.getAzureRelayNamespaceCreationParameters();
    GetAzureRelayNamespaceStep getStep = new GetAzureRelayNamespaceStep(mockAzureConfig, mockCrlService, ControlledResourceFixtures.getAzureRelayNamespace(creationParameters.getNamespaceName(), creationParameters.getRegion()));
    when(mockNamespaces.getByResourceGroup(mockAzureCloudContext.getAzureResourceGroupId(), creationParameters.getNamespaceName())).thenReturn(mockRelayNamespace);
    final StepResult stepResult = getStep.doStep(mockFlightContext);
    // Verify step returns error
    assertThat(stepResult.getStepStatus(), equalTo(StepStatus.STEP_RESULT_FAILURE_FATAL));
    assertThat(stepResult.getException().get(), instanceOf(DuplicateResourceException.class));
}
Also used : ApiAzureRelayNamespaceCreationParameters(bio.terra.workspace.generated.model.ApiAzureRelayNamespaceCreationParameters) StepResult(bio.terra.stairway.StepResult) DuplicateResourceException(bio.terra.workspace.service.resource.exception.DuplicateResourceException) Test(org.junit.jupiter.api.Test) BaseAzureTest(bio.terra.workspace.common.BaseAzureTest)

Example 3 with ApiAzureRelayNamespaceCreationParameters

use of bio.terra.workspace.generated.model.ApiAzureRelayNamespaceCreationParameters 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)

Example 4 with ApiAzureRelayNamespaceCreationParameters

use of bio.terra.workspace.generated.model.ApiAzureRelayNamespaceCreationParameters in project terra-workspace-manager by DataBiosphere.

the class CreateAzureRelayNamespaceStepTest method deleteRelayNamespace.

@Test
public void deleteRelayNamespace() throws InterruptedException {
    final ApiAzureRelayNamespaceCreationParameters creationParameters = ControlledResourceFixtures.getAzureRelayNamespaceCreationParameters();
    CreateAzureRelayNamespaceStep createStep = new CreateAzureRelayNamespaceStep(mockAzureConfig, mockCrlService, ControlledResourceFixtures.getAzureRelayNamespace(creationParameters.getNamespaceName(), creationParameters.getRegion()));
    final StepResult stepResult = createStep.undoStep(mockFlightContext);
    // Verify step returns success
    assertThat(stepResult, equalTo(StepResult.getStepResultSuccess()));
    // Verify Azure deletion was called
    verify(mockNamespaces).deleteByResourceGroup(dummyAzureCloudContext.getAzureResourceGroupId(), creationParameters.getNamespaceName());
}
Also used : ApiAzureRelayNamespaceCreationParameters(bio.terra.workspace.generated.model.ApiAzureRelayNamespaceCreationParameters) StepResult(bio.terra.stairway.StepResult) Test(org.junit.jupiter.api.Test) BaseAzureTest(bio.terra.workspace.common.BaseAzureTest)

Example 5 with ApiAzureRelayNamespaceCreationParameters

use of bio.terra.workspace.generated.model.ApiAzureRelayNamespaceCreationParameters in project terra-workspace-manager by DataBiosphere.

the class GetAzureRelayNamespaceStepTest method getRelayNamespace_doesNotExist.

@Test
public void getRelayNamespace_doesNotExist() throws InterruptedException {
    final ApiAzureRelayNamespaceCreationParameters creationParameters = ControlledResourceFixtures.getAzureRelayNamespaceCreationParameters();
    GetAzureRelayNamespaceStep getStep = new GetAzureRelayNamespaceStep(mockAzureConfig, mockCrlService, ControlledResourceFixtures.getAzureRelayNamespace(creationParameters.getNamespaceName(), creationParameters.getRegion()));
    when(mockNamespaces.getByResourceGroup(mockAzureCloudContext.getAzureResourceGroupId(), creationParameters.getNamespaceName())).thenThrow(mockException);
    final StepResult stepResult = getStep.doStep(mockFlightContext);
    // Verify step returns success
    assertThat(stepResult, equalTo(StepResult.getStepResultSuccess()));
}
Also used : ApiAzureRelayNamespaceCreationParameters(bio.terra.workspace.generated.model.ApiAzureRelayNamespaceCreationParameters) StepResult(bio.terra.stairway.StepResult) Test(org.junit.jupiter.api.Test) BaseAzureTest(bio.terra.workspace.common.BaseAzureTest)

Aggregations

BaseAzureTest (bio.terra.workspace.common.BaseAzureTest)5 ApiAzureRelayNamespaceCreationParameters (bio.terra.workspace.generated.model.ApiAzureRelayNamespaceCreationParameters)5 Test (org.junit.jupiter.api.Test)5 StepResult (bio.terra.stairway.StepResult)4 CreateRelayRequestData (bio.terra.cloudres.azure.resourcemanager.relay.data.CreateRelayRequestData)1 FlightContext (bio.terra.stairway.FlightContext)1 FlightState (bio.terra.stairway.FlightState)1 AuthenticatedUserRequest (bio.terra.workspace.service.iam.AuthenticatedUserRequest)1 ControlledAzureRelayNamespaceResource (bio.terra.workspace.service.resource.controlled.cloud.azure.relayNamespace.ControlledAzureRelayNamespaceResource)1 ControlledResource (bio.terra.workspace.service.resource.controlled.model.ControlledResource)1 DuplicateResourceException (bio.terra.workspace.service.resource.exception.DuplicateResourceException)1 AzureCloudContext (bio.terra.workspace.service.workspace.model.AzureCloudContext)1 ManagementException (com.azure.core.management.exception.ManagementException)1 Context (com.azure.core.util.Context)1 RelayManager (com.azure.resourcemanager.relay.RelayManager)1 UUID (java.util.UUID)1