Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoloboschi committed Nov 14, 2023
1 parent ff3ce29 commit bfc9ccc
Show file tree
Hide file tree
Showing 8 changed files with 182 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,9 @@ public class DeleteApplicationCmd extends BaseApplicationCmd {
public void run() {
getClient().applications().delete(applicationId, force);
if (force) {
log(
String.format(
"Application deletion request accepted (forced) for application %s",
applicationId));
log(String.format("Application '%s' marked for deletion (forced)", applicationId));
} else {
log(
String.format(
"Application deletion request accepted for application %s",
applicationId));
log(String.format("Application '%s' marked for deletion", applicationId));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -352,13 +352,25 @@ public void testGet() throws Exception {
@Test
public void testDelete() {
wireMock.register(
WireMock.delete(String.format("/api/applications/%s/my-app", TENANT))
WireMock.delete(String.format("/api/applications/%s/my-app?force=false", TENANT))
.willReturn(WireMock.ok()));

CommandResult result = executeCommand("apps", "delete", "my-app");
Assertions.assertEquals(0, result.exitCode());
Assertions.assertEquals("", result.err());
Assertions.assertEquals("Application my-app deleted", result.out());
Assertions.assertEquals("Application 'my-app' marked for deletion", result.out());
}

@Test
public void testForceDelete() {
wireMock.register(
WireMock.delete(String.format("/api/applications/%s/my-app?force=true", TENANT))
.willReturn(WireMock.ok()));

CommandResult result = executeCommand("apps", "delete", "my-app", "-f");
Assertions.assertEquals(0, result.exitCode());
Assertions.assertEquals("", result.err());
Assertions.assertEquals("Application 'my-app' marked for deletion (forced)", result.out());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,16 @@ public void testDeleteBrokenApplication() throws Exception {
"instance",
Map.of(
"streamingCluster",
Map.of("kafka", Map.of("bootstrapServers", "wrong:9092")),
Map.of(
"type",
"kafka",
"configuration",
Map.of("bootstrapServers", "wrong:9092")),
"computeCluster",
Map.of("type", "kubernetes")));

final File instanceFile = Files.createTempFile("ls-test", ".yaml").toFile();
YAML_MAPPER.writeValue(BaseEndToEndTest.instanceFile, instanceContent);
YAML_MAPPER.writeValue(instanceFile, instanceContent);

deployLocalApplication(
tenant, false, applicationId, "python-processor", instanceFile, Map.of());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1092,9 +1092,10 @@ protected static boolean isApplicationInStatus(String applicationId, String expe
return true;
}
log.info(
"application {} is not in expected status {}, dumping status",
"application {} is not in expected status {} but is in {}, dumping:",
applicationId,
expectedStatus);
expectedStatus,
status);
executeCommandOnClient(
"bin/langstream apps get %s -o yaml".formatted(applicationId).split(" "));
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,20 +110,21 @@ protected PatchResult patchResources(
final HandleJobResult setupJobResult = handleJob(resource, appLastApplied, true, false);
if (setupJobResult.proceed()) {
log.infof(
"setup job for %s is completed, checking deployer",
"[deploy] setup job for %s is completed, checking deployer",
resource.getMetadata().getName());
final HandleJobResult deployerJobResult =
handleJob(resource, appLastApplied, false, false);
log.infof(
"setup job for %s is %s",
"[deploy] setup job for %s is %s",
resource.getMetadata().getName(),
deployerJobResult.proceed() ? "completed" : "not completed");

rescheduleDuration = deployerJobResult.reschedule();
} else {

log.infof(
"setup job for %s is not completed yet", resource.getMetadata().getName());
"[deploy] setup job for %s is not completed yet",
resource.getMetadata().getName());
rescheduleDuration = setupJobResult.reschedule();
}
}
Expand All @@ -146,6 +147,9 @@ protected DeleteControl cleanupResources(
}

if (rescheduleDuration == null) {
log.infof(
"cleanup complete for app %s is completed, removing from limiter",
resource.getMetadata().getName());
appResourcesLimiter.onAppBeingDeleted(resource);
return DeleteControl.defaultDelete();
} else {
Expand All @@ -160,12 +164,12 @@ private Duration cleanupApplication(
Duration rescheduleDuration;
if (deployerJobResult.proceed()) {
log.infof(
"deployer cleanup job for %s is completed, checking setup cleanup",
"[cleanup] deployer cleanup job for %s is completed, checking setup cleanup",
resource.getMetadata().getName());

final HandleJobResult setupJobResult = handleJob(resource, appLastApplied, true, true);
log.infof(
"setup cleanup job for %s is %s",
"[cleanup] setup cleanup job for %s is %s",
resource.getMetadata().getName(),
setupJobResult.proceed() ? "completed" : "not completed");
if (setupJobResult.proceed()) {
Expand All @@ -179,7 +183,7 @@ private Duration cleanupApplication(
}
} else {
log.infof(
"deployer cleanup job for %s is not completed yet",
"[cleanup] deployer cleanup job for %s is not completed yet",
resource.getMetadata().getName());
rescheduleDuration = deployerJobResult.reschedule();
}
Expand Down Expand Up @@ -309,17 +313,22 @@ private void createJob(
setupJob
? AppResourcesFactory.generateSetupJob(params)
: AppResourcesFactory.generateDeployerJob(params);
log.debugf(
"Applying job %s in namespace %s",
job.getMetadata().getName(), job.getMetadata().getNamespace());
KubeUtil.patchJob(client, job);
}

private static boolean areSpecChanged(
ApplicationCustomResource cr, AppLastApplied appLastApplied, boolean checkSetup) {
if (appLastApplied == null) {
log.infof("Spec changed for %s, no status found", cr.getMetadata().getName());
return true;
}
final String lastAppliedAsString =
checkSetup ? appLastApplied.getSetup() : appLastApplied.getRuntimeDeployer();
if (lastAppliedAsString == null) {
log.infof("Spec changed for %s, no status found", cr.getMetadata().getName());
return true;
}
final JSONComparator.Result diff =
Expand Down
Loading

0 comments on commit bfc9ccc

Please sign in to comment.