From 1b25c8f3c0e3bab611c7febc84f4c8b302310db2 Mon Sep 17 00:00:00 2001 From: Chris Bartholomew Date: Sun, 28 Apr 2024 10:13:33 -0400 Subject: [PATCH] Adding force option to update to skip validations --- .../AbstractDeployApplicationCmd.java | 5 +++++ .../k8s/agents/PulsarDLQSourceAgentProvider.java | 8 ++++---- .../application/ApplicationResource.java | 6 ++++-- .../application/ApplicationService.java | 15 ++++++++++----- 4 files changed, 23 insertions(+), 11 deletions(-) diff --git a/langstream-cli/src/main/java/ai/langstream/cli/commands/applications/AbstractDeployApplicationCmd.java b/langstream-cli/src/main/java/ai/langstream/cli/commands/applications/AbstractDeployApplicationCmd.java index f176f1b3c..a9b97412e 100644 --- a/langstream-cli/src/main/java/ai/langstream/cli/commands/applications/AbstractDeployApplicationCmd.java +++ b/langstream-cli/src/main/java/ai/langstream/cli/commands/applications/AbstractDeployApplicationCmd.java @@ -122,6 +122,11 @@ public static class UpdateApplicationCmd extends AbstractDeployApplicationCmd { description = "Secrets file path") private String secretFilePath; + @CommandLine.Option( + names = {"--force"}, + description = "Skip validation and force update. Use with caution.") + private boolean force; + @Override String applicationId() { return name; diff --git a/langstream-k8s-runtime/langstream-k8s-runtime-core/src/main/java/ai/langstream/runtime/impl/k8s/agents/PulsarDLQSourceAgentProvider.java b/langstream-k8s-runtime/langstream-k8s-runtime-core/src/main/java/ai/langstream/runtime/impl/k8s/agents/PulsarDLQSourceAgentProvider.java index a3d5ca545..0dc3b62ad 100644 --- a/langstream-k8s-runtime/langstream-k8s-runtime-core/src/main/java/ai/langstream/runtime/impl/k8s/agents/PulsarDLQSourceAgentProvider.java +++ b/langstream-k8s-runtime/langstream-k8s-runtime-core/src/main/java/ai/langstream/runtime/impl/k8s/agents/PulsarDLQSourceAgentProvider.java @@ -59,7 +59,7 @@ public static class PulsarDLQSourceConfiguration { The URL of the Pulsar cluster to connect to. """, defaultValue = "pulsar://localhost:6650", - required = true) + required = false) @JsonProperty("pulsar-url") private String pulsarUrl; @@ -69,7 +69,7 @@ public static class PulsarDLQSourceConfiguration { Namespace to listen for DLQ topics. """, defaultValue = "public/default", - required = true) + required = false) @JsonProperty("namespace") private String namespace; @@ -79,7 +79,7 @@ public static class PulsarDLQSourceConfiguration { Subscription name to use for the DLQ topics. """, defaultValue = "langstream-dlq-subscription", - required = true) + required = false) @JsonProperty("subscription") private String subscription; @@ -89,7 +89,7 @@ public static class PulsarDLQSourceConfiguration { Suffix to use for DLQ topics. """, defaultValue = "-DLQ", - required = true) + required = false) @JsonProperty("dlq-suffix") private String dlqSuffix; diff --git a/langstream-webservice/src/main/java/ai/langstream/webservice/application/ApplicationResource.java b/langstream-webservice/src/main/java/ai/langstream/webservice/application/ApplicationResource.java index 7ec464cd0..ec9f8112b 100644 --- a/langstream-webservice/src/main/java/ai/langstream/webservice/application/ApplicationResource.java +++ b/langstream-webservice/src/main/java/ai/langstream/webservice/application/ApplicationResource.java @@ -180,7 +180,8 @@ void updateApplication( @NotBlank @PathVariable("id") String applicationId, @NotNull @RequestParam("app") Optional appFile, @RequestParam Optional instance, - @RequestParam Optional secrets) + @RequestParam Optional secrets, + @RequestParam(value = "force", required = false) Boolean force) throws Exception { performAuthorization(authentication, tenant); final ParsedApplication parsedApplication = @@ -189,7 +190,8 @@ void updateApplication( tenant, applicationId, parsedApplication.getApplication(), - parsedApplication.getCodeArchiveReference()); + parsedApplication.getCodeArchiveReference(), + force); } @Data diff --git a/langstream-webservice/src/main/java/ai/langstream/webservice/application/ApplicationService.java b/langstream-webservice/src/main/java/ai/langstream/webservice/application/ApplicationService.java index 0d9d8fde5..62befce59 100644 --- a/langstream-webservice/src/main/java/ai/langstream/webservice/application/ApplicationService.java +++ b/langstream-webservice/src/main/java/ai/langstream/webservice/application/ApplicationService.java @@ -172,17 +172,19 @@ public void updateApplication( String tenant, String applicationId, ModelBuilder.ApplicationWithPackageInfo applicationInstance, - String codeArchiveReference) { + String codeArchiveReference, + Boolean force) { checkTenant(tenant); validateDeployMergeAndUpdate( - tenant, applicationId, applicationInstance, codeArchiveReference); + tenant, applicationId, applicationInstance, codeArchiveReference, force); } private void validateDeployMergeAndUpdate( String tenant, String applicationId, ModelBuilder.ApplicationWithPackageInfo applicationInstance, - String codeArchiveReference) { + String codeArchiveReference, + Boolean force) { final StoredApplication existing = applicationStore.get(tenant, applicationId, false); if (existing == null) { @@ -191,7 +193,8 @@ private void validateDeployMergeAndUpdate( final Application newApplication = applicationInstance.getApplication(); if (!applicationInstance.isHasInstanceDefinition() && !applicationInstance.isHasSecretDefinition() - && !applicationInstance.isHasAppDefinition()) { + && !applicationInstance.isHasAppDefinition() + && !force) { throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "No changes detected"); } if (!applicationInstance.isHasInstanceDefinition()) { @@ -212,7 +215,9 @@ private void validateDeployMergeAndUpdate( newApplication.setResources(existing.getInstance().getResources()); } final ExecutionPlan newPlan = validateExecutionPlan(applicationId, newApplication); - validateUpdate(tenant, existing, existingSecrets, newPlan); + if (!force) { + validateUpdate(tenant, existing, existingSecrets, newPlan); + } if (codeArchiveReference == null) { codeArchiveReference = existing.getCodeArchiveReference(); }