diff --git a/java/operator/org.eclipse.theia.cloud.operator/src/main/java/org/eclipse/theia/cloud/operator/handler/impl/LazyStartAppDefinitionHandler.java b/java/operator/org.eclipse.theia.cloud.operator/src/main/java/org/eclipse/theia/cloud/operator/handler/impl/LazyStartAppDefinitionHandler.java index ec7bdeac..1a48133d 100644 --- a/java/operator/org.eclipse.theia.cloud.operator/src/main/java/org/eclipse/theia/cloud/operator/handler/impl/LazyStartAppDefinitionHandler.java +++ b/java/operator/org.eclipse.theia.cloud.operator/src/main/java/org/eclipse/theia/cloud/operator/handler/impl/LazyStartAppDefinitionHandler.java @@ -18,11 +18,16 @@ import static org.eclipse.theia.cloud.common.util.LogMessageUtil.formatLogMessage; +import java.util.Optional; + import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.eclipse.theia.cloud.common.k8s.client.TheiaCloudClient; import org.eclipse.theia.cloud.common.k8s.resource.AppDefinition; import org.eclipse.theia.cloud.common.k8s.resource.AppDefinitionSpec; +import org.eclipse.theia.cloud.common.k8s.resource.AppDefinitionStatus; +import org.eclipse.theia.cloud.common.k8s.resource.OperatorStatus; +import org.eclipse.theia.cloud.common.k8s.resource.ResourceStatus; import org.eclipse.theia.cloud.operator.handler.AppDefinitionHandler; import org.eclipse.theia.cloud.operator.handler.IngressPathProvider; import org.eclipse.theia.cloud.operator.handler.util.TheiaCloudIngressUtil; @@ -46,12 +51,10 @@ public boolean appDefinitionAdded(AppDefinition appDefinition, String correlatio } catch (Throwable ex) { LOGGER.error(formatLogMessage(correlationId, "An unexpected exception occurred while adding AppDefinition: " + appDefinition), ex); - // TODO update status -// client.appDefinitions().updateStatus(correlationId, appDefinition, status -> -// { -// status.setOperatorStatus(OperatorStatus.ERROR); -// status.setOperatorMessage("Unexpected error. Please check the logs for correlationId " + correlationId); -// }); + client.appDefinitions().updateStatus(correlationId, appDefinition, status -> { + status.setOperatorStatus(OperatorStatus.ERROR); + status.setOperatorMessage("Unexpected error. Please check the logs for correlationId " + correlationId); + }); return false; } } @@ -59,20 +62,26 @@ public boolean appDefinitionAdded(AppDefinition appDefinition, String correlatio protected boolean doAppDefinitionAdded(AppDefinition appDefinition, String correlationId) { LOGGER.info(formatLogMessage(correlationId, "Handling " + appDefinition)); - // TODO Check current session status and ignore if handling failed before -// Optional status = Optional.ofNullable(appDefinition.getStatus()); -// String operatorStatus = status.map(ResourceStatus::getOperatorStatus).orElse(OperatorStatus.NEW); -// if (OperatorStatus.ERROR.equals(operatorStatus) || OperatorStatus.HANDLING.equals(operatorStatus)) { -// LOGGER.warn(formatLogMessage(correlationId, -// "AppDefinition could not be handled before and is skipped now. Current status: " + operatorStatus -// + ". AppDefinition: " + appDefinition)); -// return false; -// } - - // TODO Set app definition status to being handled -// client.appDefinitions().updateStatus(correlationId, appDefinition, s -> { -// s.setOperatorStatus(OperatorStatus.HANDLING); -// }); + // Check current session status and ignore if handling failed or finished before + Optional status = Optional.ofNullable(appDefinition.getStatus()); + String operatorStatus = status.map(ResourceStatus::getOperatorStatus).orElse(OperatorStatus.NEW); + if (OperatorStatus.HANDLED.equals(operatorStatus)) { + LOGGER.trace(formatLogMessage(correlationId, + "AppDefinition was successfully handled before and is skipped now. AppDefinition: " + + appDefinition)); + return true; + } + if (OperatorStatus.ERROR.equals(operatorStatus) || OperatorStatus.HANDLING.equals(operatorStatus)) { + LOGGER.warn(formatLogMessage(correlationId, + "AppDefinition could not be handled before and is skipped now. Current status: " + operatorStatus + + ". AppDefinition: " + appDefinition)); + return false; + } + + // Set app definition status to being handled + client.appDefinitions().updateStatus(correlationId, appDefinition, s -> { + s.setOperatorStatus(OperatorStatus.HANDLING); + }); AppDefinitionSpec spec = appDefinition.getSpec(); String appDefinitionResourceName = appDefinition.getMetadata().getName(); @@ -83,20 +92,18 @@ protected boolean doAppDefinitionAdded(AppDefinition appDefinition, String corre LOGGER.error(formatLogMessage(correlationId, "Expected ingress '" + spec.getIngressname() + "' for app definition '" + appDefinitionResourceName + "' does not exist. Abort handling app definition.")); - // TODO update status - // client.appDefinitions().updateStatus(correlationId, appDefinition, s -> { -// s.setOperatorStatus(OperatorStatus.ERROR); -// s.setOperatorMessage("Ingress does not exist."); -// }); + client.appDefinitions().updateStatus(correlationId, appDefinition, s -> { + s.setOperatorStatus(OperatorStatus.ERROR); + s.setOperatorMessage("Ingress does not exist."); + }); return false; } else { LOGGER.trace(formatLogMessage(correlationId, "Ingress available already")); } - // TODO update status -// client.appDefinitions().updateStatus(correlationId, appDefinition, s -> { -// s.setOperatorStatus(OperatorStatus.HANDLED); -// }); + client.appDefinitions().updateStatus(correlationId, appDefinition, s -> { + s.setOperatorStatus(OperatorStatus.HANDLED); + }); return true; } diff --git a/java/operator/org.eclipse.theia.cloud.operator/src/main/java/org/eclipse/theia/cloud/operator/handler/impl/LazyWorkspaceHandler.java b/java/operator/org.eclipse.theia.cloud.operator/src/main/java/org/eclipse/theia/cloud/operator/handler/impl/LazyWorkspaceHandler.java index 819cd789..99ec12b2 100644 --- a/java/operator/org.eclipse.theia.cloud.operator/src/main/java/org/eclipse/theia/cloud/operator/handler/impl/LazyWorkspaceHandler.java +++ b/java/operator/org.eclipse.theia.cloud.operator/src/main/java/org/eclipse/theia/cloud/operator/handler/impl/LazyWorkspaceHandler.java @@ -61,7 +61,7 @@ public boolean workspaceAdded(Workspace workspace, String correlationId) { protected boolean doWorkspaceAdded(Workspace workspace, String correlationId) { LOGGER.info(formatLogMessage(correlationId, "Handling " + workspace)); - // Check current session status and ignore if handling failed before + // Check current session status and ignore if handling failed or finished before Optional status = Optional.ofNullable(workspace.getStatus()); String operatorStatus = status.map(ResourceStatus::getOperatorStatus).orElse(OperatorStatus.NEW); if (OperatorStatus.HANDLED.equals(operatorStatus)) {