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