Skip to content

Commit

Permalink
Initial hook up of systems to the rest of the models
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisrohr committed Mar 1, 2023
1 parent 667cbe5 commit 08e0713
Show file tree
Hide file tree
Showing 9 changed files with 121 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,9 @@ public enum Action {
* longs for the id field.
*/
private final Long recordId;

/**
* The Deployable System that this audit record is tied to
*/
Long deployableSystemId;
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,9 @@ public class Build {
private String componentVersion;
private String distributionLocation;
private Map<String, Object> extraDeploymentInfo;

/**
* The Deployable System that this build is tied to
*/
Long deployableSystemId;
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,9 @@ public class Component {
*/
String tag;

/**
* The Deployable System that this component is tied to
*/
Long deployableSystemId;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package org.kiwiproject.champagne.model;

import java.util.Optional;

import lombok.experimental.UtilityClass;

@UtilityClass
public class DeployableSystemThreadLocal {

private static final ThreadLocal<Long> THREAD_LOCAL = new ThreadLocal<>();

public static Optional<Long> getCurrentDeployableSystem() {
return Optional.ofNullable(THREAD_LOCAL.get());
}

public static void setCurrentDeployableSystem(Long id) {
THREAD_LOCAL.set(id);
}

public static void clearCurrentDeployableSystem() {
THREAD_LOCAL.remove();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,9 @@ public class DeploymentEnvironment {

boolean deleted;

/**
* The Deployable System that this env is tied to
*/
Long deployableSystemId;

}
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,9 @@ public enum Source {
* The source of truth for the definition of this host, whether it is stored in Champagne or pulled dynamically from a cloud.
*/
Source source;

/**
* The Deployable System that this host is tied to
*/
Long deployableSystemId;
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,9 @@ public class Release {

@NotBlank
String releaseNumber;

/**
* The Deployable System that this release is tied to
*/
Long deployableSystemId;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package org.kiwiproject.champagne.resource.filter;

import java.io.IOException;

import javax.ws.rs.container.ContainerRequestContext;
import javax.ws.rs.container.ContainerRequestFilter;

import org.apache.commons.lang3.StringUtils;
import org.kiwiproject.champagne.model.DeployableSystemThreadLocal;

public class DeployableSystemRequestFilter implements ContainerRequestFilter {

private static final String DEPLOYABLE_SYSTEM_HEADER_NAME = "DeployableSystem";

@Override
public void filter(ContainerRequestContext requestContext) throws IOException {
var system = requestContext.getHeaderString(DEPLOYABLE_SYSTEM_HEADER_NAME);

// TODO: Need to validate that user is in system

if (StringUtils.isNotBlank(system)) {
DeployableSystemThreadLocal.setCurrentDeployableSystem(Long.valueOf(system));
}
}

}
41 changes: 41 additions & 0 deletions service/src/main/resources/migrations.xml
Original file line number Diff line number Diff line change
Expand Up @@ -354,4 +354,45 @@
</column>
</createTable>
</changeSet>

<changeSet id="hook_up_systems" author="crohr">
<dropForeignKeyConstraint baseTableName="deployable_systems" constraintName="fk_system_deployment_environment" />
<addForeignKeyConstraint baseTableName="deployable_systems" baseColumnNames="dev_environment_id" constraintName="fk_system_deployment_environment" referencedTableName="deployment_environments" referencedColumnNames="id" />

<addColumn tableName="hosts">
<column name="deployable_system_id" type="bigint">
<constraints foreignKeyName="fk_host_deployable_system" references="deployable_systems(id)" deleteCascade="true"/>
</column>
</addColumn>

<addColumn tableName="deployment_environments">
<column name="deployable_system_id" type="bigint">
<constraints foreignKeyName="fk_deployment_environment_deployable_system" references="deployable_systems(id)" deleteCascade="true"/>
</column>
</addColumn>

<addColumn tableName="components">
<column name="deployable_system_id" type="bigint">
<constraints foreignKeyName="fk_component_deployable_system" references="deployable_systems(id)" deleteCascade="true"/>
</column>
</addColumn>

<addColumn tableName="builds">
<column name="deployable_system_id" type="bigint">
<constraints foreignKeyName="fk_build_deployable_system" references="deployable_systems(id)" deleteCascade="true"/>
</column>
</addColumn>

<addColumn tableName="audit_records">
<column name="deployable_system_id" type="bigint">
<constraints foreignKeyName="fk_audit_record_deployable_system" references="deployable_systems(id)" deleteCascade="true"/>
</column>
</addColumn>

<addColumn tableName="manual_deployment_task_releases">
<column name="deployable_system_id" type="bigint">
<constraints foreignKeyName="fk_task_deployable_system" references="deployable_systems(id)" deleteCascade="true"/>
</column>
</addColumn>
</changeSet>
</databaseChangeLog>

0 comments on commit 08e0713

Please sign in to comment.