Search in sources :

Example 1 with SpiFileSystem

use of com.sequenceiq.cloudbreak.cloud.model.SpiFileSystem in project cloudbreak by hortonworks.

the class FileSystemValidator method validate.

public void validate(String platform, CloudCredential cloudCredential, CloudStorageBase cloudStorageRequest, Long workspaceId) {
    if (cloudStorageRequest == null) {
        return;
    }
    LOGGER.info("Sending fileSystemRequest to {} to validate the file system", platform);
    CloudContext cloudContext = CloudContext.Builder.builder().withPlatform(platform).withWorkspaceId(workspaceId).build();
    SpiFileSystem spiFileSystem = cloudStorageConverter.requestToSpiFileSystem(cloudStorageRequest);
    FileSystemValidationRequest request = new FileSystemValidationRequest(spiFileSystem, cloudCredential, cloudContext);
    eventBus.notify(request.selector(), eventFactory.createEvent(request));
    try {
        FileSystemValidationResult result = request.await();
        LOGGER.info("File system validation result: {}", result);
        Exception exception = result.getErrorDetails();
        if (exception != null) {
            throw new BadRequestException(result.getStatusReason(), exception);
        }
    } catch (InterruptedException e) {
        LOGGER.error("Error while sending the file system validation request", e);
        throw new OperationException(e);
    }
}
Also used : FileSystemValidationResult(com.sequenceiq.cloudbreak.cloud.event.validation.FileSystemValidationResult) FileSystemValidationRequest(com.sequenceiq.cloudbreak.cloud.event.validation.FileSystemValidationRequest) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) SpiFileSystem(com.sequenceiq.cloudbreak.cloud.model.SpiFileSystem) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) OperationException(com.sequenceiq.cloudbreak.service.OperationException) OperationException(com.sequenceiq.cloudbreak.service.OperationException)

Example 2 with SpiFileSystem

use of com.sequenceiq.cloudbreak.cloud.model.SpiFileSystem in project cloudbreak by hortonworks.

the class CloudStorageConverter method requestToSpiFileSystem.

public SpiFileSystem requestToSpiFileSystem(CloudStorageBase cloudStorageRequest) {
    List<CloudFileSystemView> cloudFileSystemViews = new ArrayList<>();
    FileSystemType type = null;
    if (cloudStorageRequest.getIdentities() != null && !cloudStorageRequest.getIdentities().isEmpty()) {
        for (StorageIdentityBase storageIdentity : cloudStorageRequest.getIdentities()) {
            type = getCloudFileSystemView(cloudStorageRequest, cloudFileSystemViews, storageIdentity);
        }
    }
    validateCloudFileSystemViews(cloudFileSystemViews, type);
    return new SpiFileSystem("", type, cloudFileSystemViews);
}
Also used : FileSystemType(com.sequenceiq.common.model.FileSystemType) CloudFileSystemView(com.sequenceiq.cloudbreak.cloud.model.filesystem.CloudFileSystemView) ArrayList(java.util.ArrayList) SpiFileSystem(com.sequenceiq.cloudbreak.cloud.model.SpiFileSystem) StorageIdentityBase(com.sequenceiq.common.api.cloudstorage.StorageIdentityBase)

Example 3 with SpiFileSystem

use of com.sequenceiq.cloudbreak.cloud.model.SpiFileSystem in project cloudbreak by hortonworks.

the class AzureObjectStorageConnector method validateObjectStorage.

@Override
public ObjectStorageValidateResponse validateObjectStorage(ObjectStorageValidateRequest request) {
    String accountId = Crn.safeFromString(request.getCredential().getId()).getAccountId();
    if (!entitlementService.azureCloudStorageValidationEnabled(accountId)) {
        LOGGER.info("Azure Cloud storage validation entitlement is missing, not validating cloudStorageRequest: {}", JsonUtil.writeValueAsStringSilent(request));
        return ObjectStorageValidateResponse.builder().withStatus(ResponseStatus.OK).build();
    }
    AzureClient client = azureClientService.getClient(request.getCredential());
    SpiFileSystem spiFileSystem = request.getSpiFileSystem();
    ValidationResult.ValidationResultBuilder resultBuilder = new ValidationResult.ValidationResultBuilder();
    resultBuilder.prefix("Cloud Storage validation failed");
    try {
        ValidationResult validationResult = azureIDBrokerObjectStorageValidator.validateObjectStorage(client, spiFileSystem, request.getLogsLocationBase(), request.getBackupLocationBase(), getSingleResourceGroupName(request), resultBuilder);
        ObjectStorageValidateResponse response;
        if (validationResult.hasError()) {
            response = ObjectStorageValidateResponse.builder().withStatus(ResponseStatus.ERROR).withError(validationResult.getFormattedErrors()).build();
        } else {
            response = ObjectStorageValidateResponse.builder().withStatus(ResponseStatus.OK).build();
        }
        return response;
    } catch (CloudException e) {
        if (e.body() != null && StringUtils.equals("AuthorizationFailed", e.body().code())) {
            LOGGER.error("Object storage validation failed on Azure due to authorization failure: ", e.getMessage());
            throw new AccessDeniedException("Object storage validation failed on Azure due to authorization failure: ", e);
        }
        throw azureUtils.convertToCloudConnectorException(e, "Object storage validation");
    }
}
Also used : AzureClient(com.sequenceiq.cloudbreak.cloud.azure.client.AzureClient) AccessDeniedException(org.springframework.security.access.AccessDeniedException) ObjectStorageValidateResponse(com.sequenceiq.cloudbreak.cloud.model.objectstorage.ObjectStorageValidateResponse) SpiFileSystem(com.sequenceiq.cloudbreak.cloud.model.SpiFileSystem) CloudException(com.microsoft.azure.CloudException) ValidationResult(com.sequenceiq.cloudbreak.validation.ValidationResult)

Example 4 with SpiFileSystem

use of com.sequenceiq.cloudbreak.cloud.model.SpiFileSystem in project cloudbreak by hortonworks.

the class StackToCloudStackConverterTest method testConvertWhenThereIsAFileSystemInClusterThenExpectedSpiFileSystemShouldPlacedInCloudStack.

@Test
public void testConvertWhenThereIsAFileSystemInClusterThenExpectedSpiFileSystemShouldPlacedInCloudStack() {
    FileSystem fileSystem = new FileSystem();
    SpiFileSystem expected = mock(SpiFileSystem.class);
    when(cluster.getFileSystem()).thenReturn(fileSystem);
    when(fileSystemConverter.fileSystemToSpi(fileSystem)).thenReturn(expected);
    CloudStack result = underTest.convert(stack);
    assertTrue(result.getFileSystem().isPresent());
    assertEquals(expected, result.getFileSystem().get());
    verify(fileSystemConverter, times(1)).fileSystemToSpi(fileSystem);
}
Also used : FileSystem(com.sequenceiq.cloudbreak.domain.FileSystem) SpiFileSystem(com.sequenceiq.cloudbreak.cloud.model.SpiFileSystem) SpiFileSystem(com.sequenceiq.cloudbreak.cloud.model.SpiFileSystem) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 5 with SpiFileSystem

use of com.sequenceiq.cloudbreak.cloud.model.SpiFileSystem in project cloudbreak by hortonworks.

the class AzureFileSystemValidator method validate.

@Override
public void validate(AuthenticatedContext ac, CloudStack cloudStack) {
    if (cloudStack.getFileSystem().isEmpty()) {
        return;
    }
    LOGGER.info("Validation azure filesystem");
    try {
        SpiFileSystem spiFileSystem = cloudStack.getFileSystem().get();
        azureSetup.validateFileSystem(ac.getCloudCredential(), spiFileSystem);
    } catch (Exception e) {
        LOGGER.error("Error during the azure file system validation", e);
        throw new CloudConnectorException("Error during the azure file system validation", e);
    }
}
Also used : CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) SpiFileSystem(com.sequenceiq.cloudbreak.cloud.model.SpiFileSystem) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException)

Aggregations

SpiFileSystem (com.sequenceiq.cloudbreak.cloud.model.SpiFileSystem)28 ValidationResult (com.sequenceiq.cloudbreak.validation.ValidationResult)16 ValidationResultBuilder (com.sequenceiq.cloudbreak.validation.ValidationResult.ValidationResultBuilder)16 Test (org.junit.Test)15 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)7 CloudFileSystemView (com.sequenceiq.cloudbreak.cloud.model.filesystem.CloudFileSystemView)5 CloudStack (com.sequenceiq.cloudbreak.cloud.model.CloudStack)4 Identity (com.microsoft.azure.management.msi.Identity)3 AzureClient (com.sequenceiq.cloudbreak.cloud.azure.client.AzureClient)3 Group (com.sequenceiq.cloudbreak.cloud.model.Group)3 GroupNetwork (com.sequenceiq.cloudbreak.cloud.model.GroupNetwork)3 Network (com.sequenceiq.cloudbreak.cloud.model.Network)3 StorageLocationBase (com.sequenceiq.common.api.cloudstorage.StorageLocationBase)3 List (java.util.List)3 PagedList (com.microsoft.azure.PagedList)2 RoleAssignmentInner (com.microsoft.azure.management.graphrbac.implementation.RoleAssignmentInner)2 ResourceGroup (com.microsoft.azure.management.resources.ResourceGroup)2 Subscription (com.microsoft.azure.management.resources.Subscription)2 StorageAccount (com.microsoft.azure.management.storage.StorageAccount)2 AzureStorage (com.sequenceiq.cloudbreak.cloud.azure.AzureStorage)2