use of com.sequenceiq.cloudbreak.common.json.Json in project cloudbreak by hortonworks.
the class InstanceTemplateRequestToTemplateConverter method convert.
public Template convert(InstanceTemplateRequest source, CloudPlatform cloudPlatform, String accountId, String diskEncryptionSetId, String gcpKmsEncryptionKey, String awsKmsEncryptionKey) {
Template template = new Template();
template.setAccountId(accountId);
template.setName(missingResourceNameGenerator.generateName(APIResourceType.TEMPLATE));
template.setStatus(ResourceStatus.USER_MANAGED);
setVolumesProperty(source.getAttachedVolumes(), template, cloudPlatform);
template.setInstanceType(Objects.requireNonNullElse(source.getInstanceType(), defaultInstanceTypeProvider.getForPlatform(cloudPlatform.name())));
Map<String, Object> attributes = new HashMap<>();
if (cloudPlatform == CloudPlatform.AWS) {
if (awsKmsEncryptionKey != null) {
attributes.put(AwsInstanceTemplate.EBS_ENCRYPTION_ENABLED, Boolean.TRUE);
attributes.put(InstanceTemplate.VOLUME_ENCRYPTION_KEY_TYPE, EncryptionType.CUSTOM.name());
attributes.put(InstanceTemplate.VOLUME_ENCRYPTION_KEY_ID, awsKmsEncryptionKey);
} else {
attributes.put(AwsInstanceTemplate.EBS_ENCRYPTION_ENABLED, Boolean.TRUE);
attributes.put(InstanceTemplate.VOLUME_ENCRYPTION_KEY_TYPE, EncryptionType.DEFAULT.name());
}
}
Optional.ofNullable(source.getAws()).map(AwsInstanceTemplateParameters::getSpot).ifPresent(spotParameters -> {
attributes.put(AwsInstanceTemplate.EC2_SPOT_PERCENTAGE, spotParameters.getPercentage());
if (Objects.nonNull(spotParameters.getMaxPrice())) {
attributes.put(AwsInstanceTemplate.EC2_SPOT_MAX_PRICE, spotParameters.getMaxPrice());
}
});
if (cloudPlatform == CloudPlatform.AZURE) {
if (diskEncryptionSetId != null) {
attributes.put(AzureInstanceTemplate.DISK_ENCRYPTION_SET_ID, diskEncryptionSetId);
attributes.put(AzureInstanceTemplate.MANAGED_DISK_ENCRYPTION_WITH_CUSTOM_KEY_ENABLED, true);
}
if (entitlementService.isAzureEncryptionAtHostEnabled(accountId)) {
attributes.put(AzureInstanceTemplate.ENCRYPTION_AT_HOST_ENABLED, true);
}
}
if (gcpKmsEncryptionKey != null && cloudPlatform == CloudPlatform.GCP) {
attributes.put(GcpInstanceTemplate.VOLUME_ENCRYPTION_KEY_ID, gcpKmsEncryptionKey);
attributes.put(GcpInstanceTemplate.VOLUME_ENCRYPTION_KEY_TYPE, EncryptionType.CUSTOM);
attributes.put(GcpInstanceTemplate.KEY_ENCRYPTION_METHOD, KeyEncryptionMethod.KMS);
}
template.setAttributes(new Json(attributes));
return template;
}
use of com.sequenceiq.cloudbreak.common.json.Json in project cloudbreak by hortonworks.
the class StackToCloudStackConverter method buildGroupNetwork.
private GroupNetwork buildGroupNetwork(com.sequenceiq.freeipa.entity.Network network, InstanceGroup instanceGroup) {
GroupNetwork groupNetwork = null;
InstanceGroupNetwork instanceGroupNetwork = instanceGroup.getInstanceGroupNetwork();
if (instanceGroupNetwork != null) {
Json attributes = instanceGroupNetwork.getAttributes();
Map<String, Object> params = attributes == null ? Collections.emptyMap() : attributes.getMap();
Set<GroupSubnet> subnets = new HashSet<>();
if (params != null) {
List<String> subnetIds = (List<String>) params.getOrDefault(NetworkConstants.SUBNET_IDS, new ArrayList<>());
for (String subnetId : subnetIds) {
GroupSubnet groupSubnet = new GroupSubnet(subnetId);
subnets.add(groupSubnet);
}
}
groupNetwork = new GroupNetwork(network.getOutboundInternetTraffic(), subnets, params);
}
return groupNetwork;
}
use of com.sequenceiq.cloudbreak.common.json.Json in project cloudbreak by hortonworks.
the class StackToCloudStackConverter method buildInstanceTemplate.
InstanceTemplate buildInstanceTemplate(Template template, String name, Long privateId, InstanceStatus status, String instanceImageId) {
Json attributesJson = template.getAttributes();
Map<String, Object> attributes = Optional.ofNullable(attributesJson).map(Json::getMap).orElseGet(HashMap::new);
Json fromVault = template.getSecretAttributes() == null ? null : new Json(template.getSecretAttributes());
Map<String, Object> secretAttributes = Optional.ofNullable(fromVault).map(Json::getMap).orElseGet(HashMap::new);
Map<String, Object> fields = new HashMap<>();
fields.putAll(attributes);
fields.putAll(secretAttributes);
List<Volume> volumes = new ArrayList<>();
for (int i = 0; i < template.getVolumeCount(); i++) {
// FIXME figure out volume mounting
Volume volume = new Volume("/mnt/vol" + (i + 1), template.getVolumeType(), template.getVolumeSize(), CloudVolumeUsageType.GENERAL);
volumes.add(volume);
}
return new InstanceTemplate(template.getInstanceType(), name, privateId, volumes, status, fields, template.getId(), instanceImageId, TemporaryStorage.ATTACHED_VOLUMES, 0L);
}
use of com.sequenceiq.cloudbreak.common.json.Json in project cloudbreak by hortonworks.
the class StackToCloudStackConverter method buildNetwork.
private Network buildNetwork(Stack stack) {
com.sequenceiq.freeipa.entity.Network stackNetwork = stack.getNetwork();
Network result = null;
if (stackNetwork != null) {
Subnet subnet = new Subnet(null);
Json attributes = stackNetwork.getAttributes();
Map<String, Object> params = attributes == null ? Collections.emptyMap() : attributes.getMap();
result = new Network(subnet, stackNetwork.getNetworkCidrs(), stackNetwork.getOutboundInternetTraffic(), params);
}
return result;
}
use of com.sequenceiq.cloudbreak.common.json.Json in project cloudbreak by hortonworks.
the class InstanceGroupNetworkRequestToInstanceGroupNetworkConverter method convert.
public InstanceGroupNetwork convert(String cloudPlatform, @Nonnull InstanceGroupNetworkRequest source) {
InstanceGroupNetwork entity = new InstanceGroupNetwork();
entity.setCloudPlatform(cloudPlatform);
Map<String, Object> params = new HashMap<>();
InstanceGroupAwsNetworkParameters aws = source.getAws();
if (aws != null && aws.getSubnetIds() != null) {
List<String> subnetIds = aws.getSubnetIds();
params.put(NetworkConstants.SUBNET_IDS, subnetIds);
}
entity.setAttributes(new Json(params));
return entity;
}
Aggregations