Search in sources :

Example 71 with Json

use of com.sequenceiq.cloudbreak.common.json.Json in project cloudbreak by hortonworks.

the class CloudStorageValidator method validateCloudStorage.

public ObjectStorageValidateResponse validateCloudStorage(String accountId, EnvironmentCloudStorageValidationRequest environmentCloudStorageValidationRequest) {
    Credential credential = credentialService.getByCrnForAccountId(environmentCloudStorageValidationRequest.getCredentialCrn(), accountId, ENVIRONMENT, false);
    String attributes = credential.getAttributes();
    CloudCredential cloudCredential = new CloudCredential(credential.getResourceCrn(), credential.getName(), new Json(attributes).getMap(), credential.getAccountId(), credential.isVerifyPermissions());
    CloudStorageRequest cloudStorageRequest = new CloudStorageRequest();
    TelemetryRequest telemetryRequest = environmentCloudStorageValidationRequest.getTelemetry();
    boolean loggingConfigured = isLoggingConfigured(telemetryRequest);
    if (loggingConfigured) {
        LOGGER.debug("Cloud storage logging is enabled.");
        addLogIdentity(cloudStorageRequest, telemetryRequest);
    }
    ObjectStorageValidateRequest.Builder objectStorageValidateBuilder = ObjectStorageValidateRequest.builder().withCloudPlatform(credential.getCloudPlatform()).withCredential(cloudCredential).withCloudStorageRequest(cloudStorageRequest);
    if (loggingConfigured) {
        objectStorageValidateBuilder.withLogsLocationBase(telemetryRequest.getLogging().getStorageLocation());
    }
    if (environmentCloudStorageValidationRequest.getBackup() != null) {
        objectStorageValidateBuilder.withBackupLocationBase(environmentCloudStorageValidationRequest.getBackup().getStorageLocation());
    }
    ObjectStorageValidateRequest objectStorageValidateRequest = objectStorageValidateBuilder.build();
    return ThreadBasedUserCrnProvider.doAsInternalActor(regionAwareInternalCrnGeneratorFactory.iam().getInternalCrnForServiceAsString(), () -> cloudProviderServicesV4Endpoint.validateObjectStorage(objectStorageValidateRequest));
}
Also used : Credential(com.sequenceiq.environment.credential.domain.Credential) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) TelemetryRequest(com.sequenceiq.common.api.telemetry.request.TelemetryRequest) CloudStorageRequest(com.sequenceiq.common.api.cloudstorage.CloudStorageRequest) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) Json(com.sequenceiq.cloudbreak.common.json.Json) ObjectStorageValidateRequest(com.sequenceiq.cloudbreak.cloud.model.objectstorage.ObjectStorageValidateRequest)

Example 72 with Json

use of com.sequenceiq.cloudbreak.common.json.Json in project cloudbreak by hortonworks.

the class SshJClientActions method getAwsEphemeralVolumeMountPoints.

public Set<String> getAwsEphemeralVolumeMountPoints(List<InstanceGroupV4Response> instanceGroups, List<String> hostGroupNames) {
    Map<String, Pair<Integer, String>> deviceMountPointMappingsByIp = getDeviceMountPointMappingsByIp(instanceGroups, hostGroupNames, "hadoopfs");
    Map<String, Pair<Integer, String>> deviceDiskTypeMappingsByIp = getDeviceDiskTypeMappingsByIp(instanceGroups, hostGroupNames);
    Map<String, String> mountPoints = deviceDiskTypeMappingsByIp.entrySet().stream().findFirst().stream().map(node -> new Json(deviceMountPointMappingsByIp.get(node.getKey()).getValue()).getMap().entrySet()).flatMap(Set::stream).collect(Collectors.toMap(Entry::getKey, x -> String.valueOf(x.getValue())));
    return deviceDiskTypeMappingsByIp.entrySet().stream().findFirst().stream().map(node -> new Json(node.getValue().getValue()).getMap().entrySet().stream().filter(e -> String.valueOf(e.getValue()).contains("Amazon EC2 NVMe Instance Storage")).collect(Collectors.toMap(Entry::getKey, x -> String.valueOf(x.getValue())))).map(Map::keySet).flatMap(Set::stream).map(mountPoints::get).collect(Collectors.toSet());
}
Also used : FreeIpaTestDto(com.sequenceiq.it.cloudbreak.dto.freeipa.FreeIpaTestDto) SshJClient(com.sequenceiq.it.cloudbreak.util.ssh.client.SshJClient) LoggerFactory(org.slf4j.LoggerFactory) StringUtils(org.apache.commons.lang3.StringUtils) CollectionUtils(org.apache.commons.collections4.CollectionUtils) ArrayList(java.util.ArrayList) Pair(org.apache.commons.lang3.tuple.Pair) TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException) Map(java.util.Map) FreeIpaClient(com.sequenceiq.it.cloudbreak.FreeIpaClient) SdxTestDto(com.sequenceiq.it.cloudbreak.dto.sdx.SdxTestDto) Logger(org.slf4j.Logger) Collection(java.util.Collection) Log(com.sequenceiq.it.cloudbreak.log.Log) Set(java.util.Set) InstanceGroupV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.instancegroup.InstanceGroupV4Response) InstanceMetaDataResponse(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.instance.InstanceMetaDataResponse) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) DistroXTestDto(com.sequenceiq.it.cloudbreak.dto.distrox.DistroXTestDto) Objects(java.util.Objects) Json(com.sequenceiq.cloudbreak.common.json.Json) AtomicLong(java.util.concurrent.atomic.AtomicLong) List(java.util.List) Component(org.springframework.stereotype.Component) Stream(java.util.stream.Stream) AbstractSdxTestDto(com.sequenceiq.it.cloudbreak.dto.AbstractSdxTestDto) SSHClient(net.schmizz.sshj.SSHClient) Entry(java.util.Map.Entry) Entry(java.util.Map.Entry) Set(java.util.Set) Json(com.sequenceiq.cloudbreak.common.json.Json) Pair(org.apache.commons.lang3.tuple.Pair)

Example 73 with Json

use of com.sequenceiq.cloudbreak.common.json.Json in project cloudbreak by hortonworks.

the class SshJClientActions method checkAwsEphemeralDisksMounted.

public void checkAwsEphemeralDisksMounted(List<InstanceGroupV4Response> instanceGroups, List<String> hostGroupNames, String mountDirPrefix) {
    Map<String, Pair<Integer, String>> deviceMountPointMappingsByIp = getDeviceMountPointMappingsByIp(instanceGroups, hostGroupNames, "hadoopfs");
    Map<String, Pair<Integer, String>> deviceDiskTypeMappingsByIp = getDeviceDiskTypeMappingsByIp(instanceGroups, hostGroupNames);
    for (Entry<String, Pair<Integer, String>> node : deviceDiskTypeMappingsByIp.entrySet()) {
        Map<String, String> ephemeralDisks = new Json(node.getValue().getValue()).getMap().entrySet().stream().filter(e -> String.valueOf(e.getValue()).contains("Amazon EC2 NVMe Instance Storage")).collect(Collectors.toMap(Entry::getKey, x -> String.valueOf(x.getValue())));
        if (ephemeralDisks.isEmpty()) {
            LOGGER.error("Instance store volume missing from node with IP {}!", node.getKey());
            throw new TestFailException(format("Instance store volume missing from node with IP %s!", node.getKey()));
        }
        if (deviceMountPointMappingsByIp.get(node.getKey()) == null) {
            LOGGER.error("No device mount point mappings found for node with IP {}!", node.getKey());
            throw new TestFailException(format("No device mount point mappings found for node with IP %s!", node.getKey()));
        }
        Map<String, String> mountPoints = new Json(deviceMountPointMappingsByIp.get(node.getKey()).getValue()).getMap().entrySet().stream().collect(Collectors.toMap(Entry::getKey, x -> String.valueOf(x.getValue())));
        for (String device : ephemeralDisks.keySet()) {
            String mountPoint = mountPoints.get(device);
            if (mountPoint == null) {
                LOGGER.error("No mount point found for ephemeral device {} on node with IP {}!", device, node.getKey());
                throw new TestFailException(format("No mount point found for device %s on node with IP %s!", device, node.getKey()));
            } else if (!mountPoint.contains(mountDirPrefix)) {
                LOGGER.error("Ephemeral device {} incorrectly mounted to {} on node with IP {}!", device, mountPoint, node.getKey());
                throw new TestFailException(format("Ephemeral device %s incorrectly mounted to %s on node with IP %s!", device, mountPoint, node.getKey()));
            }
        }
    }
}
Also used : FreeIpaTestDto(com.sequenceiq.it.cloudbreak.dto.freeipa.FreeIpaTestDto) SshJClient(com.sequenceiq.it.cloudbreak.util.ssh.client.SshJClient) LoggerFactory(org.slf4j.LoggerFactory) StringUtils(org.apache.commons.lang3.StringUtils) CollectionUtils(org.apache.commons.collections4.CollectionUtils) ArrayList(java.util.ArrayList) Pair(org.apache.commons.lang3.tuple.Pair) TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException) Map(java.util.Map) FreeIpaClient(com.sequenceiq.it.cloudbreak.FreeIpaClient) SdxTestDto(com.sequenceiq.it.cloudbreak.dto.sdx.SdxTestDto) Logger(org.slf4j.Logger) Collection(java.util.Collection) Log(com.sequenceiq.it.cloudbreak.log.Log) Set(java.util.Set) InstanceGroupV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.instancegroup.InstanceGroupV4Response) InstanceMetaDataResponse(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.instance.InstanceMetaDataResponse) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) DistroXTestDto(com.sequenceiq.it.cloudbreak.dto.distrox.DistroXTestDto) Objects(java.util.Objects) Json(com.sequenceiq.cloudbreak.common.json.Json) AtomicLong(java.util.concurrent.atomic.AtomicLong) List(java.util.List) Component(org.springframework.stereotype.Component) Stream(java.util.stream.Stream) AbstractSdxTestDto(com.sequenceiq.it.cloudbreak.dto.AbstractSdxTestDto) SSHClient(net.schmizz.sshj.SSHClient) Entry(java.util.Map.Entry) TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException) Json(com.sequenceiq.cloudbreak.common.json.Json) Pair(org.apache.commons.lang3.tuple.Pair)

Example 74 with Json

use of com.sequenceiq.cloudbreak.common.json.Json in project cloudbreak by hortonworks.

the class StackToTemplatePreparationObjectConverterTest method testConvertWhenEnvironmentBackupLocationDefinedThenBaseFileSystemConfigurationsViewShouldAddIt.

@Test
public void testConvertWhenEnvironmentBackupLocationDefinedThenBaseFileSystemConfigurationsViewShouldAddIt() throws IOException {
    String backupLocation = "s3a://test";
    FileSystem sourceFileSystem = new FileSystem();
    FileSystem clusterServiceFileSystem = new FileSystem();
    ConfigQueryEntries configQueryEntries = new ConfigQueryEntries();
    BaseFileSystemConfigurationsView expected = mock(BaseFileSystemConfigurationsView.class);
    List<StorageLocationView> storageLocationViews = mock(List.class);
    BackupResponse backupResponse = new BackupResponse();
    backupResponse.setStorageLocation(backupLocation);
    DetailedEnvironmentResponse environmentResponse = DetailedEnvironmentResponse.builder().withIdBrokerMappingSource(IdBrokerMappingSource.MOCK).withCredential(new CredentialResponse()).withAdminGroupName(ADMIN_GROUP_NAME).withCrn(TestConstants.CRN).withBackup(backupResponse).build();
    StorageLocation storageLocation = new StorageLocation();
    storageLocation.setValue(backupLocation);
    storageLocation.setProperty(RangerCloudStorageServiceConfigProvider.DEFAULT_BACKUP_DIR);
    StorageLocationView backupLocationView = new StorageLocationView(storageLocation);
    when(sourceCluster.getFileSystem()).thenReturn(sourceFileSystem);
    when(cluster.getFileSystem()).thenReturn(clusterServiceFileSystem);
    when(fileSystemConfigurationProvider.fileSystemConfiguration(eq(clusterServiceFileSystem), eq(stackMock), any(), eq(new Json("")), eq(configQueryEntries))).thenReturn(expected);
    when(cmCloudStorageConfigProvider.getConfigQueryEntries()).thenReturn(configQueryEntries);
    when(environmentClientService.getByCrn(anyString())).thenReturn(environmentResponse);
    when(blueprintViewProvider.getBlueprintView(any())).thenReturn(getBlueprintView());
    when(expected.getLocations()).thenReturn(storageLocationViews);
    TemplatePreparationObject result = underTest.convert(stackMock);
    assertThat(result.getFileSystemConfigurationView().isPresent()).isTrue();
    assertThat(result.getFileSystemConfigurationView().get()).isEqualTo(expected);
    verify(fileSystemConfigurationProvider, times(1)).fileSystemConfiguration(eq(clusterServiceFileSystem), eq(stackMock), any(), eq(new Json("")), eq(configQueryEntries));
    verify(expected, times(1)).getLocations();
    verify(storageLocationViews, times(1)).add(eq(backupLocationView));
}
Also used : TemplatePreparationObject(com.sequenceiq.cloudbreak.template.TemplatePreparationObject) StorageLocationView(com.sequenceiq.cloudbreak.template.filesystem.StorageLocationView) BaseFileSystemConfigurationsView(com.sequenceiq.cloudbreak.template.filesystem.BaseFileSystemConfigurationsView) FileSystem(com.sequenceiq.cloudbreak.domain.FileSystem) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) CredentialResponse(com.sequenceiq.environment.api.v1.credential.model.response.CredentialResponse) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Json(com.sequenceiq.cloudbreak.common.json.Json) BackupResponse(com.sequenceiq.common.api.backup.response.BackupResponse) StorageLocation(com.sequenceiq.cloudbreak.domain.StorageLocation) ConfigQueryEntries(com.sequenceiq.common.api.cloudstorage.query.ConfigQueryEntries) Test(org.junit.jupiter.api.Test)

Example 75 with Json

use of com.sequenceiq.cloudbreak.common.json.Json in project cloudbreak by hortonworks.

the class MockPatchServiceTest method setStackTag.

private void setStackTag(String tagValue) {
    StackTags stackTags = new StackTags(Map.of(STACK_PATCH_RESULT_TAG_KEY, tagValue), Map.of(), Map.of());
    stack.setTags(new Json(stackTags));
}
Also used : StackTags(com.sequenceiq.cloudbreak.cloud.model.StackTags) Json(com.sequenceiq.cloudbreak.common.json.Json)

Aggregations

Json (com.sequenceiq.cloudbreak.common.json.Json)266 Test (org.junit.jupiter.api.Test)95 HashMap (java.util.HashMap)49 InstanceTemplate (com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate)31 Template (com.sequenceiq.freeipa.entity.Template)26 AwsInstanceTemplate (com.sequenceiq.cloudbreak.cloud.model.instance.AwsInstanceTemplate)25 List (java.util.List)24 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)24 AzureInstanceTemplate (com.sequenceiq.cloudbreak.cloud.model.instance.AzureInstanceTemplate)23 Map (java.util.Map)22 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)21 InstanceMetaData (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData)21 ArrayList (java.util.ArrayList)21 Test (org.junit.Test)21 InstanceGroup (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup)20 IOException (java.io.IOException)20 Cluster (com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster)18 RestRequestDetails (com.sequenceiq.cloudbreak.structuredevent.event.rest.RestRequestDetails)16 DetailedEnvironmentResponse (com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse)16 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)14