Search in sources :

Example 81 with Json

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

the class DBStackToDatabaseStackConverterTest method testConversionGcpWithGcpEncryptionResourcesPresent.

@Test
public void testConversionGcpWithGcpEncryptionResourcesPresent() {
    Network network = new Network();
    network.setAttributes(new Json(NETWORK_ATTRIBUTES));
    dbStack.setNetwork(network);
    dbStack.setCloudPlatform("GCP");
    dbStack.setParameters(new HashMap<>());
    DatabaseServer server = new DatabaseServer();
    server.setDatabaseVendor(DatabaseVendor.POSTGRES);
    server.setAttributes(new Json(DATABASE_SERVER_ATTRIBUTES));
    dbStack.setDatabaseServer(server);
    dbStack.setTags(new Json(STACK_TAGS));
    dbStack.setTemplate("template");
    DetailedEnvironmentResponse environmentResponse = new DetailedEnvironmentResponse();
    environmentResponse.setCloudPlatform("GCP");
    environmentResponse.setGcp(GcpEnvironmentParameters.builder().withResourceEncryptionParameters(GcpResourceEncryptionParameters.builder().withEncryptionKey("value").build()).build());
    when(environmentService.getByCrn(anyString())).thenReturn(environmentResponse);
    DatabaseStack convertedStack = underTest.convert(dbStack);
    Map<String, Object> parameters = convertedStack.getDatabaseServer().getParameters();
    assertThat(parameters.get("key").toString()).isEqualTo("value");
    assertThat(parameters.size()).isEqualTo(3);
}
Also used : Network(com.sequenceiq.redbeams.domain.stack.Network) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) DatabaseStack(com.sequenceiq.cloudbreak.cloud.model.DatabaseStack) DatabaseServer(com.sequenceiq.redbeams.domain.stack.DatabaseServer) Json(com.sequenceiq.cloudbreak.common.json.Json) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.jupiter.api.Test)

Example 82 with Json

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

the class DBStackToDatabaseStackConverterTest method testConversionAwsWithAwsEncryptionResourcesPresent.

@Test
public void testConversionAwsWithAwsEncryptionResourcesPresent() {
    Network network = new Network();
    network.setAttributes(new Json(NETWORK_ATTRIBUTES));
    dbStack.setNetwork(network);
    dbStack.setCloudPlatform("AWS");
    dbStack.setParameters(new HashMap<>());
    DatabaseServer server = new DatabaseServer();
    server.setDatabaseVendor(DatabaseVendor.POSTGRES);
    server.setAttributes(new Json(DATABASE_SERVER_ATTRIBUTES));
    dbStack.setDatabaseServer(server);
    dbStack.setTags(new Json(STACK_TAGS));
    dbStack.setTemplate("template");
    DetailedEnvironmentResponse environmentResponse = new DetailedEnvironmentResponse();
    environmentResponse.setCloudPlatform("AWS");
    environmentResponse.setAws(AwsEnvironmentParameters.builder().withAwsDiskEncryptionParameters(AwsDiskEncryptionParameters.builder().withEncryptionKeyArn("value").build()).build());
    when(environmentService.getByCrn(anyString())).thenReturn(environmentResponse);
    DatabaseStack convertedStack = underTest.convert(dbStack);
    Map<String, Object> parameters = convertedStack.getDatabaseServer().getParameters();
    assertThat(parameters.get("key").toString()).isEqualTo("value");
    assertThat(parameters.size()).isEqualTo(3);
}
Also used : Network(com.sequenceiq.redbeams.domain.stack.Network) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) DatabaseStack(com.sequenceiq.cloudbreak.cloud.model.DatabaseStack) DatabaseServer(com.sequenceiq.redbeams.domain.stack.DatabaseServer) Json(com.sequenceiq.cloudbreak.common.json.Json) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.jupiter.api.Test)

Example 83 with Json

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

the class LoadBalancerConfigServiceTest method createStack.

private Stack createStack(StackType type, String subnetId, String cloudPlatform, boolean makePrivate) {
    Cluster cluster = new Cluster();
    cluster.setBlueprint(blueprint);
    Set<InstanceGroup> instanceGroups = new HashSet<>();
    InstanceGroup instanceGroup1 = new InstanceGroup();
    instanceGroup1.setGroupName("master");
    instanceGroup1.setAttributes(new Json(new HashMap<String, Object>()));
    InstanceGroup instanceGroup2 = new InstanceGroup();
    instanceGroup2.setGroupName("manager");
    instanceGroup2.setAttributes(new Json(new HashMap<String, Object>()));
    instanceGroups.add(instanceGroup1);
    instanceGroups.add(instanceGroup2);
    InstanceMetaData imd1 = new InstanceMetaData();
    InstanceMetaData imd2 = new InstanceMetaData();
    Set<InstanceMetaData> imdSet = Set.of(imd1, imd2);
    instanceGroup1.setInstanceMetaData(imdSet);
    instanceGroup2.setInstanceMetaData(imdSet);
    Stack stack = new Stack();
    stack.setType(type);
    stack.setCluster(cluster);
    stack.setInstanceGroups(instanceGroups);
    stack.setCloudPlatform(cloudPlatform);
    Network network = new Network();
    Map<String, Object> attributes = new HashMap<>();
    if (StringUtils.isNotEmpty(subnetId)) {
        attributes.put("subnetId", subnetId);
    }
    if (AZURE.equals(cloudPlatform)) {
        attributes.put("noPublicIp", makePrivate);
        InstanceGroup instanceGroup3 = new InstanceGroup();
        instanceGroup3.setGroupName("worker");
        instanceGroups.add(instanceGroup3);
    }
    network.setAttributes(new Json(attributes));
    stack.setNetwork(network);
    return stack;
}
Also used : HashMap(java.util.HashMap) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) Json(com.sequenceiq.cloudbreak.common.json.Json) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) InstanceGroup(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) Network(com.sequenceiq.cloudbreak.domain.Network) HashSet(java.util.HashSet)

Example 84 with Json

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

the class MultiAzCalculatorServiceTest method calculateByRoundRobinTestWhenCloudInstanceAndNoSubnetIds.

@ParameterizedTest(name = "{0}")
@MethodSource("calculateByRoundRobinTestWhenCloudInstanceAndNoSubnetIdsDataProvider")
void calculateByRoundRobinTestWhenCloudInstanceAndNoSubnetIds(String testCaseName, boolean disableNetwork, boolean disableAttributes, boolean disableSubnetIdsAttribute, boolean prepopulateCloudInstanceSubnet) {
    InstanceGroup instanceGroup = instanceGroup(CloudPlatform.AWS, SINGLE_INSTANCE, NO_SUBNETS);
    if (disableNetwork) {
        instanceGroup.setInstanceGroupNetwork(null);
    } else if (disableAttributes) {
        instanceGroup.getInstanceGroupNetwork().setAttributes(null);
    } else if (disableSubnetIdsAttribute) {
        instanceGroup.getInstanceGroupNetwork().setAttributes(new Json(Map.of()));
    }
    String cloudInstanceSubnetId = prepopulateCloudInstanceSubnet ? SUBNET_ID : null;
    String cloudInstanceAvailabilityZone = prepopulateCloudInstanceSubnet ? AVAILABILITY_ZONE : null;
    InstanceMetaData instanceMetaData = new InstanceMetaData();
    instanceMetaData.setSubnetId(cloudInstanceSubnetId);
    instanceMetaData.setAvailabilityZone(cloudInstanceAvailabilityZone);
    underTest.calculateByRoundRobin(subnetAzPairs(NO_SUBNETS), instanceGroup, instanceMetaData, NetworkScaleDetails.getEmpty());
    verifyCloudInstance(cloudInstanceSubnetId == null ? Set.of() : Set.of(cloudInstanceSubnetId), cloudInstanceAvailabilityZone == null ? Set.of() : Set.of(cloudInstanceAvailabilityZone), instanceMetaData);
    instanceGroup.getAllInstanceMetaData().forEach(instance -> {
        assertThat(instance.getSubnetId()).isNull();
        assertThat(instance.getAvailabilityZone()).isNull();
    });
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) Json(com.sequenceiq.cloudbreak.common.json.Json) InstanceGroup(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 85 with Json

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

the class MultiAzCalculatorServiceTest method calculateByRoundRobinTestWhenWholeInstanceGroupAndNoSubnetIds.

@ParameterizedTest(name = "{0}")
@MethodSource("calculateByRoundRobinTestWhenWholeInstanceGroupAndNoSubnetIdsDataProvider")
void calculateByRoundRobinTestWhenWholeInstanceGroupAndNoSubnetIds(String testCaseName, boolean disableNetwork, boolean disableAttributes, boolean disableSubnetIdsAttribute) {
    InstanceGroup instanceGroup = instanceGroup(CloudPlatform.AWS, SINGLE_INSTANCE, NO_SUBNETS);
    if (disableNetwork) {
        instanceGroup.setInstanceGroupNetwork(null);
    } else if (disableAttributes) {
        instanceGroup.getInstanceGroupNetwork().setAttributes(null);
    } else if (disableSubnetIdsAttribute) {
        instanceGroup.getInstanceGroupNetwork().setAttributes(new Json(Map.of()));
    }
    underTest.calculateByRoundRobin(subnetAzPairs(NO_SUBNETS), instanceGroup);
    instanceGroup.getAllInstanceMetaData().forEach(instance -> {
        assertThat(instance.getSubnetId()).isNull();
        assertThat(instance.getAvailabilityZone()).isNull();
    });
}
Also used : Json(com.sequenceiq.cloudbreak.common.json.Json) InstanceGroup(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

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