Skip to content

Commit

Permalink
Merge branch 'release/0.15.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
clivebor committed Jul 14, 2022
2 parents 76dad07 + 8fd7e16 commit 238f493
Show file tree
Hide file tree
Showing 122 changed files with 3,306 additions and 1,466 deletions.
2 changes: 1 addition & 1 deletion ahoy-components/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<parent>
<groupId>za.co.lsd.ahoy</groupId>
<artifactId>ahoy</artifactId>
<version>0.14.0</version>
<version>0.15.0</version>
</parent>
<artifactId>ahoy-components</artifactId>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,11 @@ public ResponseEntity<Void> copyApplicationVersionEnvConfig(@PathVariable Long r
return new ResponseEntity<>(null, new HttpHeaders(), HttpStatus.OK);
}

@PostMapping("/releases/{releaseId}/duplicate")
public ResponseEntity<Release> duplicate(@PathVariable Long releaseId, @RequestBody DuplicateOptions duplicateOptions) {
@PostMapping("/releases/duplicate/{sourceReleaseId}/{destReleaseId}")
public ResponseEntity<Release> duplicate(@PathVariable Long sourceReleaseId, @PathVariable Long destReleaseId,
@RequestBody DuplicateOptions duplicateOptions) {

Release duplicatedRelease = releaseService.duplicate(releaseId, duplicateOptions);
Release duplicatedRelease = releaseService.duplicate(sourceReleaseId, destReleaseId, duplicateOptions);
return new ResponseEntity<>(duplicatedRelease, new HttpHeaders(), HttpStatus.OK);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,29 +228,30 @@ public ReleaseVersion upgrade(Long releaseVersionId, UpgradeOptions upgradeOptio
}

@Transactional
public Release duplicate(Long releaseId, DuplicateOptions duplicateOptions) {
Release sourceRelease = releaseRepository.findById(releaseId)
.orElseThrow(() -> new ResourceNotFoundException("Could not find source release: " + releaseId));
public Release duplicate(Long sourceReleaseId, Long destReleaseId, DuplicateOptions duplicateOptions) {
Release sourceRelease = releaseRepository.findById(sourceReleaseId)
.orElseThrow(() -> new ResourceNotFoundException("Could not find source release: " + sourceReleaseId));

Release duplicatedRelease = releaseRepository.save(new Release(duplicateOptions.getReleaseName()));
log.debug("Duplicated release: {} for source release: {}", duplicatedRelease, sourceRelease);
Release destRelease = releaseRepository.findById(destReleaseId)
.orElseThrow(() -> new ResourceNotFoundException("Could not find destination release: " + sourceReleaseId));
log.debug("Duplicating release: {} to release: {} with options: {}", sourceRelease, destRelease, duplicateOptions);

for (ReleaseVersion sourceReleaseVersion : sourceRelease.getReleaseVersions()) {
ReleaseVersion duplicatedReleaseVersion = new ReleaseVersion(sourceReleaseVersion.getVersion());
duplicatedRelease.addReleaseVersion(duplicatedReleaseVersion);
destRelease.addReleaseVersion(duplicatedReleaseVersion);
duplicatedReleaseVersion.setApplicationVersions(new ArrayList<>(sourceReleaseVersion.getApplicationVersions()));
duplicatedReleaseVersion = releaseVersionRepository.save(duplicatedReleaseVersion);
log.debug("Duplicated release version: {} for source release version: {}", duplicatedReleaseVersion, sourceReleaseVersion);
}

if (duplicateOptions.isAddToSameEnvironments()) {
for (EnvironmentRelease sourceEnvRelease : sourceRelease.getEnvironmentReleases()) {
EnvironmentRelease duplicatedEnvRelease = new EnvironmentRelease(sourceEnvRelease.getEnvironment(), duplicatedRelease);
EnvironmentRelease duplicatedEnvRelease = new EnvironmentRelease(sourceEnvRelease.getEnvironment(), destRelease);
duplicatedEnvRelease = environmentReleaseRepository.save(duplicatedEnvRelease);
log.debug("Duplicated environment release: {} for source environment release: {}", duplicatedEnvRelease.getId(), sourceEnvRelease.getId());

if (duplicateOptions.isCopyEnvironmentConfig()) {
for (ReleaseVersion destReleaseVersion : duplicatedRelease.getReleaseVersions()) {
for (ReleaseVersion destReleaseVersion : destRelease.getReleaseVersions()) {
ReleaseVersion sourceReleaseVersion = sourceRelease.getReleaseVersions().stream()
.filter(rv -> rv.getVersion().equals(destReleaseVersion.getVersion()))
.findFirst()
Expand All @@ -265,7 +266,7 @@ public Release duplicate(Long releaseId, DuplicateOptions duplicateOptions) {
}
}

return duplicatedRelease;
return destRelease;
}

@Transactional
Expand Down Expand Up @@ -347,21 +348,30 @@ public Flux<PodLog> getLogs(EnvironmentReleaseId environmentReleaseId,
/**
* Copies environment config from one release version to another for the same environment release.
*/
private void copyEnvironmentConfig(EnvironmentRelease environmentRelease, ReleaseVersion sourceReleaseVersion, ReleaseVersion destReleaseVersion) {
this.copyEnvironmentConfig(environmentRelease, sourceReleaseVersion, environmentRelease, destReleaseVersion);
public void copyEnvironmentConfig(EnvironmentRelease environmentRelease, ReleaseVersion sourceReleaseVersion, ReleaseVersion destReleaseVersion) {
copyEnvironmentConfig(environmentRelease, sourceReleaseVersion, environmentRelease, destReleaseVersion);
}

/**
* Copies environment config from one environment release to another for all its release versions. Usually used when duplicating and environment with all its releases.
*/
public void copyEnvironmentConfig(EnvironmentRelease sourceEnvironmentRelease, EnvironmentRelease destEnvironmentRelease) {
for (ReleaseVersion releaseVersion : sourceEnvironmentRelease.getRelease().getReleaseVersions()) {
copyEnvironmentConfig(sourceEnvironmentRelease, destEnvironmentRelease, releaseVersion);
}
}

/**
* Copies environment config from one environment release to another for the same version.
*/
private void copyEnvironmentConfig(EnvironmentRelease sourceEnvironmentRelease, EnvironmentRelease destEnvironmentRelease, ReleaseVersion releaseVersion) {
this.copyEnvironmentConfig(sourceEnvironmentRelease, releaseVersion, destEnvironmentRelease, releaseVersion);
public void copyEnvironmentConfig(EnvironmentRelease sourceEnvironmentRelease, EnvironmentRelease destEnvironmentRelease, ReleaseVersion releaseVersion) {
copyEnvironmentConfig(sourceEnvironmentRelease, releaseVersion, destEnvironmentRelease, releaseVersion);
}

/**
* Copies environment config from one environment release version to another environment release version.
*/
private void copyEnvironmentConfig(EnvironmentRelease sourceEnvironmentRelease, ReleaseVersion sourceReleaseVersion, EnvironmentRelease destEnvironmentRelease, ReleaseVersion destReleaseVersion) {
public void copyEnvironmentConfig(EnvironmentRelease sourceEnvironmentRelease, ReleaseVersion sourceReleaseVersion, EnvironmentRelease destEnvironmentRelease, ReleaseVersion destReleaseVersion) {
for (ApplicationVersion applicationVersion : destReleaseVersion.getApplicationVersions()) {
copyEnvironmentConfig(sourceEnvironmentRelease, sourceReleaseVersion, applicationVersion, destEnvironmentRelease, destReleaseVersion, applicationVersion);
}
Expand All @@ -370,7 +380,7 @@ private void copyEnvironmentConfig(EnvironmentRelease sourceEnvironmentRelease,
/**
* Copies environment config from one application version to another for the same release version and environment.
*/
private void copyEnvironmentConfig(EnvironmentRelease environmentRelease, ReleaseVersion releaseVersion, ApplicationVersion sourceApplicationVersion, ApplicationVersion destApplicationVersion) {
public void copyEnvironmentConfig(EnvironmentRelease environmentRelease, ReleaseVersion releaseVersion, ApplicationVersion sourceApplicationVersion, ApplicationVersion destApplicationVersion) {
copyEnvironmentConfig(environmentRelease, releaseVersion, sourceApplicationVersion, environmentRelease, releaseVersion, destApplicationVersion);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,55 +60,55 @@ public boolean hasReplicas() {
}

public boolean routeEnabled() {
return spec != null && spec.getRouteEnabled() != null && spec.getRouteEnabled();
return spec != null && spec.isRouteEnabled();
}

public boolean hasRoute() {
return spec != null && spec.getRouteHostname() != null && !spec.getRouteHostname().trim().isEmpty() && spec.getRouteTargetPort() != null;
}

public boolean environmentVariablesEnabled() {
return spec != null && spec.getEnvironmentVariablesEnabled() != null && spec.getEnvironmentVariablesEnabled();
return spec != null && spec.isEnvironmentVariablesEnabled();
}

public boolean hasEnvironmentVariables() {
return spec != null && spec.getEnvironmentVariables() != null && spec.getEnvironmentVariables().size() > 0;
}

public boolean configEnabled() {
return spec != null && spec.getConfigFilesEnabled() != null && spec.getConfigFilesEnabled();
return spec != null && spec.isConfigFilesEnabled();
}

public boolean hasConfigs() {
return spec != null && spec.getConfigFiles() != null && spec.getConfigFiles().size() > 0;
}

public boolean volumesEnabled() {
return spec != null && spec.getVolumesEnabled() != null && spec.getVolumesEnabled();
return spec != null && spec.isVolumesEnabled();
}

public boolean hasVolumes() {
return spec != null && spec.getVolumes() != null && spec.getVolumes().size() > 0;
}

public boolean secretsEnabled() {
return spec != null && spec.getSecretsEnabled() != null && spec.getSecretsEnabled();
return spec != null && spec.isSecretsEnabled();
}

public boolean hasSecrets() {
return spec != null && spec.getSecrets() != null && spec.getSecrets().size() > 0;
}

public boolean resourcesEnabled() {
return spec != null && spec.getResourcesEnabled() != null && spec.getResourcesEnabled();
return spec != null && spec.isResourcesEnabled();
}

public boolean hasResources() {
return spec != null && spec.getResources() != null;
}

public ApplicationEnvironmentSpec summarySpec() {
return ApplicationEnvironmentSpec.newSummarySpec(spec.getRouteEnabled(), spec.getRouteHostname());
return ApplicationEnvironmentSpec.newSummarySpec(spec.isRouteEnabled(), spec.getRouteHostname());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,25 @@
public class ApplicationEnvironmentSpec {
private Integer replicas;

private Boolean routeEnabled;
private boolean routeEnabled;
private String routeHostname;
private Integer routeTargetPort;
private boolean tls;
private String tlsSecretName;

private Boolean environmentVariablesEnabled;
private boolean environmentVariablesEnabled;
private List<ApplicationEnvironmentVariable> environmentVariables;

private Boolean configFilesEnabled;
private boolean configFilesEnabled;
private List<ApplicationConfigFile> configFiles;

private Boolean volumesEnabled;
private boolean volumesEnabled;
private List<ApplicationVolume> volumes;

private Boolean secretsEnabled;
private boolean secretsEnabled;
private List<ApplicationSecret> secrets;

private Boolean resourcesEnabled;
private boolean resourcesEnabled;
private ApplicationResources resources;

public static ApplicationEnvironmentSpec newSummarySpec(Boolean routeEnabled, String routeHostname) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@
public class ApplicationSpec extends ContainerSpec {
private String dockerRegistryName;

private Boolean configFilesEnabled;
private boolean configFilesEnabled;
private String configPath;
private List<ApplicationConfigFile> configFiles;

private Boolean volumesEnabled;
private boolean volumesEnabled;
private List<ApplicationVolume> volumes;

private Boolean secretsEnabled;
private boolean secretsEnabled;
private List<ApplicationSecret> secrets;

private List<ContainerSpec> containers = new ArrayList<>();
Expand All @@ -49,26 +49,14 @@ public ApplicationSpec(String name, String image, String dockerRegistryName) {
this.dockerRegistryName = dockerRegistryName;
}

public boolean configEnabled() {
return configFilesEnabled != null && configFilesEnabled;
}

public boolean hasConfigs() {
return configFiles != null && configFiles.size() > 0;
}

public boolean volumesEnabled() {
return volumesEnabled != null && volumesEnabled;
}

public boolean hasVolumes() {
return volumes != null && volumes.size() > 0;
}

public boolean secretsEnabled() {
return secretsEnabled != null && secretsEnabled;
}

public boolean hasSecrets() {
return secrets != null && secrets.size() > 0;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class DockerRegistry {
@ToString.Exclude
private String password;
@ToString.Exclude
private Boolean secure;
private boolean secure;

public DockerRegistry(String name, String server, String username, String password) {
this.name = name;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright 2022 LSD Information Technology (Pty) Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package za.co.lsd.ahoy.server.environments;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class DuplicateOptions {
private boolean copyEnvironmentConfig;
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.hibernate.Hibernate;
import za.co.lsd.ahoy.server.cluster.Cluster;
import za.co.lsd.ahoy.server.environmentrelease.EnvironmentRelease;
import za.co.lsd.ahoy.server.releases.ReleaseHistory;

import javax.persistence.*;
import javax.validation.constraints.NotNull;
Expand Down Expand Up @@ -61,6 +62,12 @@ public class Environment implements Serializable {
@ToString.Exclude
private List<EnvironmentRelease> environmentReleases = new ArrayList<>();

@OneToMany(mappedBy = "environment", cascade = CascadeType.REMOVE, orphanRemoval = true)
@OrderBy("id")
@JsonIgnore
@ToString.Exclude
private List<ReleaseHistory> releaseHistories = new ArrayList<>();

public Environment(@NotNull String name) {
this.name = name;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,20 +69,24 @@ public Environment destroy(Environment environment) {
}

@Transactional
public Environment duplicate(Long sourceEnvironmentId, Long destEnvironmentId) {
public Environment duplicate(Long sourceEnvironmentId, Long destEnvironmentId, DuplicateOptions duplicateOptions) {
Environment sourceEnvironment = environmentRepository.findById(sourceEnvironmentId)
.orElseThrow(() -> new ResourceNotFoundException("Could not find source environment: " + sourceEnvironmentId));

Environment destEnvironment = environmentRepository.findById(destEnvironmentId)
.orElseThrow(() -> new ResourceNotFoundException("Could not find destination environment: " + destEnvironmentId));

log.info("Duplicating environment {} to environment {}", sourceEnvironment, destEnvironment);
log.info("Duplicating environment {} to environment {} with options {}", sourceEnvironment, destEnvironment, duplicateOptions);

List<EnvironmentRelease> sourceEnvironmentReleases = sourceEnvironment.getEnvironmentReleases();
for (EnvironmentRelease sourceEnvironmentRelease : sourceEnvironmentReleases) {

EnvironmentRelease newEnvironmentRelease = new EnvironmentRelease(destEnvironment, sourceEnvironmentRelease.getRelease());
environmentReleaseRepository.save(newEnvironmentRelease);

if (duplicateOptions.isCopyEnvironmentConfig()) {
releaseService.copyEnvironmentConfig(sourceEnvironmentRelease, newEnvironmentRelease);
}
}
return destEnvironment;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,17 @@ public ResponseEntity<Environment> destroy(@PathVariable Long environmentId) {
}

@PostMapping("/duplicate/{sourceEnvironmentId}/{destEnvironmentId}")
public ResponseEntity<Environment> duplicate(@PathVariable Long sourceEnvironmentId, @PathVariable Long destEnvironmentId) {
public ResponseEntity<Environment> duplicate(@PathVariable Long sourceEnvironmentId, @PathVariable Long destEnvironmentId,
@RequestBody DuplicateOptions duplicateOptions) {

Environment destEnvironment = environmentService.duplicate(sourceEnvironmentId, destEnvironmentId);
Environment destEnvironment = environmentService.duplicate(sourceEnvironmentId, destEnvironmentId, duplicateOptions);

return new ResponseEntity<>(destEnvironment, new HttpHeaders(), HttpStatus.OK);
}

@PostMapping("/{environmentId}/move")
public ResponseEntity<Environment> move(@PathVariable Long environmentId, @RequestBody MoveOptions moveOptions) {
public ResponseEntity<Environment> move(@PathVariable Long environmentId,
@RequestBody MoveOptions moveOptions) {

Environment destEnvironment = environmentService.move(environmentId, moveOptions);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,23 +74,23 @@ public void writeTemplates(EnvironmentRelease environmentRelease, ReleaseVersion

ApplicationSpec applicationSpec = applicationVersion.getSpec();

if ((applicationSpec.configEnabled() && applicationSpec.hasConfigs()) ||
if ((applicationSpec.isConfigFilesEnabled() && applicationSpec.hasConfigs()) ||
applicationEnvironmentConfig.map(e -> e.configEnabled() && e.hasConfigs()).orElse(false)) {
addTemplate(application, "configmap", templatesPath, trackedTemplates);
}

if ((applicationSpec.volumesEnabled() && applicationSpec.hasVolumes()) ||
if ((applicationSpec.isVolumesEnabled() && applicationSpec.hasVolumes()) ||
applicationEnvironmentConfig.map(e -> e.volumesEnabled() && e.hasVolumes()).orElse(false)) {
addTemplate(application, "pvc", templatesPath, trackedTemplates);
}

if ((applicationSpec.secretsEnabled() && applicationSpec.hasSecrets()) ||
if ((applicationSpec.isSecretsEnabled() && applicationSpec.hasSecrets()) ||
applicationEnvironmentConfig.map(e -> e.secretsEnabled() && e.hasSecrets()).orElse(false)) {
addTemplate(application, "secret-generic", templatesPath, trackedTemplates);
}

Optional<DockerRegistry> dockerRegistry = dockerRegistryProvider.dockerRegistryFor(applicationSpec.getDockerRegistryName());
if (dockerRegistry.isPresent() && dockerRegistry.get().getSecure()) {
if (dockerRegistry.isPresent() && dockerRegistry.get().isSecure()) {
addTemplate(application, "secret-dockerconfig", templatesPath, trackedTemplates);
}

Expand Down
Loading

0 comments on commit 238f493

Please sign in to comment.