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

support new Url config fields #577

Merged
merged 5 commits into from
Nov 27, 2023
Merged
Changes from 1 commit
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
Expand Up @@ -24,6 +24,8 @@

import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
import java.io.BufferedInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
Expand Down Expand Up @@ -209,7 +211,9 @@ public DeployJob.DeploySummary latest () {
public String routerId;

public String customBuildConfig;
public String customBuildConfigUrl;
public String customRouterConfig;
public String customRouterConfigUrl;

public List<CustomFile> customFiles = new ArrayList<>();

Expand Down Expand Up @@ -414,9 +418,44 @@ public void dump (File output, boolean includeManifest, boolean includeOsm, bool
out.close();
}

private byte[] downloadFileFromURL(URL url) throws IOException {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();

InputStream stream = null;
try {
byte[] chunk = new byte[4096];
philip-cline marked this conversation as resolved.
Show resolved Hide resolved
int bytesRead;
stream = url.openStream();

while ((bytesRead = stream.read(chunk)) > 0) {
outputStream.write(chunk, 0, bytesRead);
}

} catch (IOException e) {
e.printStackTrace();
return new byte[0];
} finally {
outputStream.close();
if (stream != null) stream.close();
}

return outputStream.toByteArray();
}

/** Generate build config for deployment as byte array (for writing to file output stream). */
public byte[] generateBuildConfig() {
Project project = this.parentProject();

// If there is a custombuildconfigUrl, set the customBuildConfig based on the URL
if (this.customBuildConfigUrl != null) {
try {
this.customBuildConfig = new String(downloadFileFromURL(new URL(customBuildConfigUrl)), StandardCharsets.UTF_8);
} catch (IOException e) {
LOG.error("Could not download file from {}", customBuildConfigUrl);
throw new RuntimeException(customBuildConfigUrl);
}
}

return customBuildConfig != null
? customBuildConfig.getBytes(StandardCharsets.UTF_8)
: project.buildConfig != null
Expand Down Expand Up @@ -453,6 +492,16 @@ private <O extends Serializable> String writeToString(O object) {
public byte[] generateRouterConfig() throws IOException {
Project project = this.parentProject();

if (this.customRouterConfigUrl != null) {
try {
// TODO: should Mongo be updated here?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this comment be added above the line for this.customBuildConfig as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The question is targeted at you. Is leaving the comment the best bet do you think?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If not here, where will it be updated?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well I think in this line instead of updating the local instantiated Deployment we'd update Mongo

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right I see what you're saying now. Updating the mongo might be more in line with what we do currently elsewhere

this.customRouterConfig = new String(downloadFileFromURL(new URL(customRouterConfigUrl)), StandardCharsets.UTF_8);
} catch (IOException e) {
LOG.error("Could not download file from {}", customRouterConfigUrl);
throw new RuntimeException(e);
}
}

byte[] customRouterConfigString = customRouterConfig != null
? customRouterConfig.getBytes(StandardCharsets.UTF_8)
: null;
Expand Down
Loading