use of io.stackgres.apiweb.dto.cluster.ClusterPostgres in project stackgres by ongres.
the class ClusterTransformer method getResourceSpec.
private ClusterSpec getResourceSpec(StackGresClusterSpec source) {
if (source == null) {
return null;
}
ClusterSpec transformation = new ClusterSpec();
transformation.setPostgres(new ClusterPostgres());
transformation.getPostgres().setVersion(source.getPostgres().getVersion());
transformation.getPostgres().setExtensions(Optional.ofNullable(source.getPostgres().getExtensions()).stream().flatMap(List::stream).map(this::getResourceExtension).collect(ImmutableList.toImmutableList()));
final StackGresClusterSsl sourceClusterSsl = source.getPostgres().getSsl();
if (sourceClusterSsl != null) {
transformation.getPostgres().setSsl(new ClusterSsl());
transformation.getPostgres().getSsl().setEnabled(sourceClusterSsl.getEnabled());
transformation.getPostgres().getSsl().setCertificateSecretKeySelector(sourceClusterSsl.getCertificateSecretKeySelector());
transformation.getPostgres().getSsl().setPrivateKeySecretKeySelector(sourceClusterSsl.getPrivateKeySecretKeySelector());
}
transformation.setConfigurations(new ClusterConfiguration());
transformation.getConfigurations().setSgBackupConfig(source.getConfiguration().getBackupConfig());
transformation.getConfigurations().setSgPoolingConfig(source.getConfiguration().getConnectionPoolingConfig());
transformation.setInstances(source.getInstances());
transformation.setNonProduction(getResourceNonProduction(source.getNonProduction()));
transformation.getConfigurations().setSgPostgresConfig(source.getConfiguration().getPostgresConfig());
transformation.setPrometheusAutobind(source.getPrometheusAutobind());
transformation.setSgInstanceProfile(source.getResourceProfile());
final StackGresClusterInitData sourceInitData = source.getInitData();
if (sourceInitData != null) {
ClusterInitData targetInitData = new ClusterInitData();
transformation.setInitData(targetInitData);
final StackGresClusterRestore sourceRestore = sourceInitData.getRestore();
if (sourceRestore != null) {
targetInitData.setRestore(getResourceRestore(sourceRestore));
}
if (sourceInitData.getScripts() != null) {
targetInitData.setScripts(sourceInitData.getScripts().stream().map(sourceEntry -> {
ClusterScriptEntry targetEntry = new ClusterScriptEntry();
targetEntry.setScript(sourceEntry.getScript());
targetEntry.setDatabase(sourceEntry.getDatabase());
targetEntry.setName(sourceEntry.getName());
if (sourceEntry.getScriptFrom() != null) {
targetEntry.setScriptFrom(new ClusterScriptFrom());
targetEntry.getScriptFrom().setSecretKeyRef(sourceEntry.getScriptFrom().getSecretKeyRef());
targetEntry.getScriptFrom().setConfigMapKeyRef(sourceEntry.getScriptFrom().getConfigMapKeyRef());
}
return targetEntry;
}).collect(ImmutableList.toImmutableList()));
}
}
final ClusterPod targetPod = new ClusterPod();
final StackGresClusterPod sourcePod = source.getPod();
transformation.setPods(targetPod);
targetPod.setPersistentVolume(new ClusterPodPersistentVolume());
targetPod.getPersistentVolume().setStorageClass(sourcePod.getPersistentVolume().getStorageClass());
targetPod.getPersistentVolume().setSize(sourcePod.getPersistentVolume().getSize());
targetPod.setDisableConnectionPooling(sourcePod.getDisableConnectionPooling());
targetPod.setDisableMetricsExporter(sourcePod.getDisableMetricsExporter());
targetPod.setDisablePostgresUtil(sourcePod.getDisablePostgresUtil());
final StackGresClusterSpecMetadata specMetadata = source.getMetadata();
if (specMetadata != null) {
transformation.setMetadata(new ClusterSpecMetadata());
final StackGresClusterSpecAnnotations sourceAnnotations = specMetadata.getAnnotations();
if (specMetadata.getAnnotations() != null) {
ClusterSpecAnnotations targetAnnotations = new ClusterSpecAnnotations();
targetAnnotations.setAllResources(sourceAnnotations.getAllResources());
targetAnnotations.setClusterPods(sourceAnnotations.getClusterPods());
targetAnnotations.setServices(sourceAnnotations.getServices());
targetAnnotations.setPrimaryService(sourceAnnotations.getPrimaryService());
targetAnnotations.setReplicasService(sourceAnnotations.getReplicasService());
transformation.getMetadata().setAnnotations(targetAnnotations);
}
final StackGresClusterSpecLabels sourceLabels = specMetadata.getLabels();
if (sourceLabels != null) {
ClusterSpecLabels targetLabels = new ClusterSpecLabels();
targetLabels.setClusterPods(sourceLabels.getClusterPods());
transformation.getMetadata().setLabels(targetLabels);
}
}
final StackGresClusterPostgresServices sourcePostgresServices = source.getPostgresServices();
if (sourcePostgresServices != null) {
transformation.setPostgresServices(new ClusterPostgresServices());
final ClusterPostgresServices targetPostgresService = transformation.getPostgresServices();
final StackGresPostgresService sourcePrimaryService = sourcePostgresServices.getPrimary();
if (sourcePrimaryService != null) {
targetPostgresService.setPrimary(new PostgresService());
targetPostgresService.getPrimary().setType(sourcePrimaryService.getType());
targetPostgresService.getPrimary().setEnabled(sourcePrimaryService.getEnabled());
}
final StackGresPostgresService sourceReplicaService = sourcePostgresServices.getReplicas();
if (sourceReplicaService != null) {
targetPostgresService.setReplicas(new PostgresService());
targetPostgresService.getReplicas().setEnabled(sourceReplicaService.getEnabled());
targetPostgresService.getReplicas().setType(sourceReplicaService.getType());
}
}
targetPod.setScheduling(Optional.ofNullable(sourcePod.getScheduling()).map(sourcePodScheduling -> {
return new ClusterPodSchedulingConverter().from(sourcePodScheduling);
}).orElse(null));
transformation.setDistributedLogs(getResourceDistributedLogs(source.getDistributedLogs()));
if (source.getToInstallPostgresExtensions() != null) {
transformation.setToInstallPostgresExtensions(source.getToInstallPostgresExtensions().stream().map(this::getClusterInstalledExtension).collect(ImmutableList.toImmutableList()));
}
return transformation;
}
Aggregations