Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unused gigajar functionality #1122

Merged
merged 1 commit into from
Dec 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,21 +1,15 @@
package uk.gov.hmcts.rse.ccd.lib;

import java.io.File;
import java.io.IOException;
import java.lang.reflect.Method;
import java.net.URL;
import java.net.URLClassLoader;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;

import static java.lang.System.getenv;

Expand All @@ -41,9 +35,6 @@ public static void main(String[] args) throws Exception {
private static void doRun(String[] args) {
Thread.currentThread().setName("**** cftlib bootstrap");
setConfigProperties();
if (args.length == 0) {
args = extractRuntime();
}
var threads = new ArrayList<Thread>();
{
var runtime = args[0];
Expand Down Expand Up @@ -127,36 +118,6 @@ private static void setConfigProperties() {
}


@SneakyThrows
public static String[] extractRuntime() throws IOException {
// Turn off devtools when packaged as a jar.
System.setProperty("spring.devtools.restart.enabled", "false");
var is = LibRunner.class.getResourceAsStream("/cftlib-runtime.zip");

if (null != is) {
try (ZipInputStream zipIn = new ZipInputStream(is)) {
for (ZipEntry ze; (ze = zipIn.getNextEntry()) != null; ) {
var targetDir = Paths.get("");
Path resolvedPath = targetDir.resolve(ze.getName()).normalize();
if (ze.isDirectory()) {
Files.createDirectories(resolvedPath);
} else {
Files.createDirectories(resolvedPath.getParent());
Files.copy(zipIn, resolvedPath, StandardCopyOption.REPLACE_EXISTING);
}
}
}
}

var result =
Stream.concat(Stream.of("build/cftlib/runtime_packed"),
Files.list(Paths.get("build/cftlib"))
.filter(x -> !x.getFileName().endsWith("runtime_packed"))
.map(x -> x.toAbsolutePath().toString()))
.toArray(String[]::new);
return result;
}

@SneakyThrows
private static void launchApp(File classpathFile) {
// We must initially use a thread name of 'main' for spring boot devtools to work.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,7 @@ public void importJsonDefinition(File defFolder) {

@SneakyThrows
private void postDefinition(byte[] data) {
// Route the request via the gateway embedded in the runtime project.
// Our port is overridable
var port = ControlPlane.getEnvVar("RSE_LIB_S2S_PORT", 8489);
HttpPost uploadFile = new HttpPost("http://localhost:" + port + "/import");
HttpPost uploadFile = new HttpPost("http://localhost:4451/import");
uploadFile.addHeader("Authorization", "Bearer " + buildJwt());
uploadFile.addHeader("ServiceAuthorization", generateDummyS2SToken("ccd_gw"));
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
Expand Down
24 changes: 0 additions & 24 deletions cftlib/lib/runtime/src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -1,28 +1,4 @@
server:
port:
${RSE_LIB_S2S_PORT:8489}
spring:
cloud:
gateway:
routes:
- id: definitionstore
uri: http://localhost:4451
predicates:
- Path=/import,/api/import-audits,/api/user-role
- id: datastore
uri: http://localhost:4452
predicates:
- Path=/aggregated/**,/data/**,/case-types/**,/searchCases,/cases/**,/case-users,/caseworkers/**,/citizens/**
- id: am
uri: http://localhost:4096
predicates:
- Path=/am/**
- id: application
uri: http://localhost:4013
predicates:
- Path=/**

ccd:
definition:
paths:
NFD: src/test/resources/definition/
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import java.io.File;
import java.io.FileWriter;
import java.io.PrintWriter;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
Expand All @@ -12,20 +11,15 @@
import com.google.common.base.Function;
import com.google.common.base.Joiner;
import com.google.common.collect.Lists;
import com.google.common.collect.ObjectArrays;
import lombok.SneakyThrows;
import org.gradle.api.Plugin;
import org.gradle.api.Project;
import org.gradle.api.artifacts.Configuration;
import org.gradle.api.artifacts.Dependency;
import org.gradle.api.file.Directory;
import org.gradle.api.file.DuplicatesStrategy;
import org.gradle.api.file.FileCollection;
import org.gradle.api.file.RelativePath;
import org.gradle.api.tasks.JavaExec;
import org.gradle.api.tasks.SourceSetContainer;
import org.gradle.api.tasks.bundling.Zip;
import org.gradle.api.tasks.bundling.ZipEntryCompression;
import org.gradle.jvm.tasks.Jar;

public class CftLibPlugin implements Plugin<Project> {
Expand Down Expand Up @@ -54,7 +48,6 @@ public void apply(Project project) {
createTestTask(project);
surfaceSourcesToIDE(project);
createCftlibJarTask(project);
createExecutableJarTask(project, createZipRuntimeTask(project));
}

static Directory cftlibBuildDir(Project project) {
Expand All @@ -75,73 +68,13 @@ private void registerDependencyRepositories(Project project) {
});
}

@SneakyThrows
private Zip createZipRuntimeTask(Project project) {
var zip = project.getTasks().create("cftlibRuntimeArchive", Zip.class);
zip.getArchiveFileName().set("cftlib-runtime.zip");
// Jars are already compressed so switch off compression.
zip.setEntryCompression(ZipEntryCompression.STORED);
zip.setDuplicatesStrategy(DuplicatesStrategy.EXCLUDE);
zip.from(cftlibBuildDir(project), z -> {
z.include("**/*_packed");
z.exclude("**/*libTest*");
});

zip.eachFile(f -> {
f.setRelativePath(zipPath(project, f.getFile()));
});

for (ManifestTask manifestTask : manifestTasks) {
zip.from(manifestTask.classpath, x -> x.into("lib"));
zip.dependsOn(manifestTask);
}
return zip;
}

/**
* Calculate the correct path that files should be placed inside the zip file.
* We pack files from both the project folder (into 'build') and Gradle's dependency cache (into 'lib').
*/
@SneakyThrows
private RelativePath zipPath(Project project, File f) {
var projectRoot = project.getLayout().getBuildDirectory().get().dir("../").getAsFile().getCanonicalPath();
if (f.getCanonicalPath().startsWith(projectRoot)) {
// File should go into 'build'
var relativePath = Paths.get(projectRoot).relativize(f.toPath());
return RelativePath.parse(true, relativePath.toString());
} else {
// File should go into 'lib'
var p = RelativePath.parse(true, f.getPath());
// The last 4 segments of the jar's directory path include its group, name and version.
var tail = Arrays.copyOfRange(p.getSegments(), p.getSegments().length - 4, p.getSegments().length);
var result = ObjectArrays.concat("lib", tail);
return new RelativePath(true, result);
}
}

private void createCftlibJarTask(Project project) {
var jar = project.getTasks().create("cftlibJar", Jar.class);
jar.getArchiveFileName().set("cftlib-application.jar");
SourceSetContainer s = project.getExtensions().getByType(SourceSetContainer.class);
jar.from(s.getByName("main").getOutput().plus(s.getByName("cftlib").getOutput()));
}

private void createExecutableJarTask(Project project, Zip archive) {

var jar = project.getTasks().create("cftlibExecutableJar", Jar.class);
jar.dependsOn(manifestTasks);
jar.manifest(x -> x.attributes(Map.of("Main-Class", "uk.gov.hmcts.rse.ccd.lib.LibRunner")));
jar.getArchiveFileName().set("cftlib-executable.jar");

jar.setEntryCompression(ZipEntryCompression.STORED);
jar.doFirst(t -> {
jar.from(project.zipTree(
detachedConfiguration(project, libDependencies(project, "bootstrapper"))
.getSingleFile()));
});
jar.from(archive);
}

private Configuration detachedConfiguration(Project project, Dependency... deps) {
var result = project.getConfigurations().detachedConfiguration(deps);
// We don't want Gradle to swap in dependency substitutions in composite builds.
Expand Down Expand Up @@ -309,8 +242,6 @@ private void writeManifests(Project project, FileCollection classpath, String ma
String... args) {
cftlibBuildDir(project).getAsFile().mkdirs();
writeManifest(file, mainClass, classpath, File::getAbsolutePath, args);
writeManifest(new File(file.getPath() + "_packed"), mainClass, classpath,
x -> zipPath(project, x).getPathString(), args);
}

@SneakyThrows
Expand Down
12 changes: 0 additions & 12 deletions cftlib/test-project/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -89,18 +89,6 @@ tasks.test.dependsOn(cftlibTest)
cftlibTest.dependsOn(rootProject.tasks.publish)
cftlibTestClasses.dependsOn(rootProject.tasks.publish)

// Relies on bootWithCCD starting up the dockerised dependencies.
task testGigaJar(type: uk.gov.hmcts.rse.CftlibExec, dependsOn: [cftlibExecutableJar, bootWithCCD]) {
workingDir project.layout.buildDirectory.dir('gigatest')
outputs.dir workingDir
authMode = AuthMode.Local
main = "-jar"
environment 'CFT_LIB_NO_DOCKER', true
args cftlibExecutableJar.archiveFile.get()
}

tasks.test.dependsOn(testGigaJar)

task publishSecrets(type: Exec) {
commandLine 'az', 'keyvault', 'secret', 'set', "--vault-name", "rse-cft-lib", "--name", "aat-env", "--file", layout.buildDirectory.file('cftlib/.aat-env').get().asFile.path
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public static String buildJwt() {
@SneakyThrows
@Test
void testController() {
var request = buildGet("http://localhost:7431/index");
var request = buildGet("http://localhost:7431/health");
var response = HttpClientBuilder.create().build().execute(request);
assertThat(response.getStatusLine().getStatusCode(), equalTo(200));
}
Expand Down Expand Up @@ -96,7 +96,7 @@ void invalidS2STokenReturnsUnauthorised() {
@SneakyThrows
@Test
void listJurisdictions() {
var request = buildGet("http://localhost:7431/aggregated/caseworkers/:uid/jurisdictions?access=read");
var request = buildGet("http://localhost:4452/aggregated/caseworkers/:uid/jurisdictions?access=read");
// Test xui talking direct to ccd without the gateway.
// The s2s subject should be rewritten to ccd_gw by the lib.
request.removeHeaders("ServiceAuthorization");
Expand All @@ -113,7 +113,7 @@ void listJurisdictions() {
@SneakyThrows
@Test
void getWorkbasketInputs() {
var request = buildGet("http://localhost:7431/data/internal/case-types/NFD/work-basket-inputs");
var request = buildGet("http://localhost:4452/data/internal/case-types/NFD/work-basket-inputs");
request.addHeader("experimental", "true");

var response = HttpClientBuilder.create().build().execute(request);
Expand All @@ -130,7 +130,7 @@ void getWorkbasketInputs() {
@Test
void getPaginationMetadata() {
var request = buildGet(
"http://localhost:7431/data/caseworkers/:uid/jurisdictions/DIVORCE/case-types/NFD/cases/pagination_metadata");
"http://localhost:4452/data/caseworkers/:uid/jurisdictions/DIVORCE/case-types/NFD/cases/pagination_metadata");

var response = HttpClientBuilder.create().build().execute(request);
assertThat(response.getStatusLine().getStatusCode(), equalTo(200));
Expand Down Expand Up @@ -188,7 +188,7 @@ void testRoleAssignments() {
@Test
void caseCreation() throws IOException {
var request = buildGet(
"http://localhost:7431/data/internal/case-types/NFD/event-triggers/create-test-application?ignore-warning=false");
"http://localhost:4452/data/internal/case-types/NFD/event-triggers/create-test-application?ignore-warning=false");
request.addHeader("experimental", "true");
request.addHeader("Accept",
"application/vnd.uk.gov.hmcts.ccd-data-store-api.ui-start-case-trigger.v2+json;charset=UTF-8");
Expand Down
Loading