Search in sources :

Example 91 with Json

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

the class DefaultInstanceGroupProviderTest method createDefaultTemplateTestVolumeEncryptionAddedWhenAzureAndEncryptionAtHostEnabled.

@Test
void createDefaultTemplateTestVolumeEncryptionAddedWhenAzureAndEncryptionAtHostEnabled() {
    when(entitlementService.isAzureEncryptionAtHostEnabled(ACCOUNT_ID)).thenReturn(Boolean.TRUE);
    Template result = underTest.createDefaultTemplate(CloudPlatform.AZURE, ACCOUNT_ID, "dummyDiskEncryptionSet", null, null);
    assertThat(result).isNotNull();
    Json attributes = result.getAttributes();
    assertThat(attributes).isNotNull();
    assertThat(attributes.<Object>getValue(AzureInstanceTemplate.DISK_ENCRYPTION_SET_ID)).isEqualTo("dummyDiskEncryptionSet");
    assertThat(attributes.<Object>getValue(AzureInstanceTemplate.MANAGED_DISK_ENCRYPTION_WITH_CUSTOM_KEY_ENABLED)).isEqualTo(Boolean.TRUE);
    assertThat(attributes.<Object>getValue(AzureInstanceTemplate.ENCRYPTION_AT_HOST_ENABLED)).isEqualTo(Boolean.TRUE);
}
Also used : JSONObject(net.sf.json.JSONObject) Json(com.sequenceiq.cloudbreak.common.json.Json) Template(com.sequenceiq.freeipa.entity.Template) InstanceTemplate(com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate) AzureInstanceTemplate(com.sequenceiq.cloudbreak.cloud.model.instance.AzureInstanceTemplate) AwsInstanceTemplate(com.sequenceiq.cloudbreak.cloud.model.instance.AwsInstanceTemplate) Test(org.junit.jupiter.api.Test)

Example 92 with Json

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

the class DefaultInstanceGroupProviderTest method createDefaultNetworkWithAwsAttributesShouldReturnWithNetworkAttributes.

@Test
void createDefaultNetworkWithAwsAttributesShouldReturnWithNetworkAttributes() {
    Json json = new Json(Map.of(NetworkConstants.SUBNET_IDS, Set.of("id")));
    NetworkRequest network = new NetworkRequest();
    AwsNetworkParameters awsNetworkParameters = new AwsNetworkParameters();
    awsNetworkParameters.setSubnetId("id");
    network.setAws(awsNetworkParameters);
    InstanceGroupNetwork defaultNetwork = underTest.createDefaultNetwork(CloudPlatform.AWS, network);
    assertThat(defaultNetwork.getAttributes()).isEqualTo(json);
}
Also used : NetworkRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.network.NetworkRequest) AwsNetworkParameters(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.network.AwsNetworkParameters) Json(com.sequenceiq.cloudbreak.common.json.Json) InstanceGroupNetwork(com.sequenceiq.freeipa.entity.InstanceGroupNetwork) Test(org.junit.jupiter.api.Test)

Example 93 with Json

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

the class ServiceProviderCredentialAdapter method mergeCloudProviderParameters.

private boolean mergeCloudProviderParameters(Credential credential, CloudCredential cloudCredentialResponse, Set<String> skippedKeys, boolean overrideParameters) {
    Json attributes = new Json(credential.getAttributes());
    Map<String, Object> newAttributes = attributes.getMap();
    boolean newAttributesAdded = false;
    for (Entry<String, Object> cloudParam : cloudCredentialResponse.getParameters().entrySet()) {
        if (!skippedKeys.contains(cloudParam.getKey()) && cloudParam.getValue() != null) {
            if (overrideParameters || newAttributes.get(cloudParam.getKey()) == null) {
                newAttributes.put(cloudParam.getKey(), cloudParam.getValue());
                newAttributesAdded = true;
            }
        }
    }
    if (newAttributesAdded) {
        credential.setAttributes(new Json(newAttributes).getValue());
    }
    return newAttributesAdded;
}
Also used : Json(com.sequenceiq.cloudbreak.common.json.Json)

Example 94 with Json

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

the class CredentialToCredentialV1ResponseConverter method convert.

public Credential convert(ExtendedCloudCredential source) {
    if (source == null) {
        return null;
    }
    Credential credential = new Credential();
    credential.setName(source.getName());
    credential.setDescription(source.getDescription());
    credential.setCloudPlatform(source.getCloudPlatform());
    credential.setCreator(source.getUserCrn());
    credential.setAccountId(source.getAccountId());
    Map<String, Object> attributes = source.getParameters() == null ? new HashMap<>() : source.getParameters();
    credential.setAttributes(new Json(attributes).getValue());
    return credential;
}
Also used : ExtendedCloudCredential(com.sequenceiq.cloudbreak.cloud.model.ExtendedCloudCredential) Credential(com.sequenceiq.environment.credential.domain.Credential) Json(com.sequenceiq.cloudbreak.common.json.Json)

Example 95 with Json

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

the class CredentialV1RequestToCredentialConverter method convertAttributes.

private void convertAttributes(CredentialRequest source, Credential credential) {
    CredentialAttributes credentialAttributes = new CredentialAttributes();
    doIfNotNull(source.getAws(), param -> credentialAttributes.setAws(awsConverter.convert(param)));
    doIfNotNull(source.getAzure(), param -> credentialAttributes.setAzure(azureConverter.convert(param)));
    doIfNotNull(source.getGcp(), param -> credentialAttributes.setGcp(gcpConverter.convert(param)));
    doIfNotNull(source.getMock(), param -> credentialAttributes.setMock(mockConverter.convert(param)));
    doIfNotNull(source.getYarn(), param -> credentialAttributes.setYarn(yarnConverter.convert(param)));
    credential.setAttributes(new Json(credentialAttributes).getValue());
}
Also used : CredentialAttributes(com.sequenceiq.environment.credential.attributes.CredentialAttributes) 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