Search in sources :

Example 1 with AppInfo

use of com.enonic.kubernetes.apis.xp.service.AppInfo in project xp-operator by enonic.

the class HandlerInstall method doInstallApp.

private void doInstallApp(final Xp7Deployment deployment, final Xp7App app) {
    // Try to install
    try {
        AppInfo appInfo = xpClientCache.appInstall(app.getMetadata().getNamespace(), deployment.getMetadata().getName(), app.getSpec().getUrl(), app.getSpec().getSha512());
        handlerStatus.updateStatus(app, appInfo);
    } catch (Exception e) {
        log.warn(String.format("Failed installing app %s in NS %s: %s", app.getMetadata().getName(), app.getMetadata().getNamespace(), e.getMessage()));
        handlerStatus.updateStatus(app, "Cannot install, see operator logs");
    }
}
Also used : AppInfo(com.enonic.kubernetes.apis.xp.service.AppInfo)

Example 2 with AppInfo

use of com.enonic.kubernetes.apis.xp.service.AppInfo in project xp-operator by enonic.

the class HandlerStatus method updateStatus.

private boolean updateStatus(final Optional<Xp7App> optionalApp, final Optional<Xp7Deployment> optionalDeployment, final Optional<AppInfo> optionalAppInfo, final Optional<String> error) {
    if (optionalApp.isEmpty()) {
        // This can happen if apps are installed in XP but not with the operator
        return false;
    }
    Xp7App app = optionalApp.get();
    if (error.isPresent()) {
        return setStatus(app, Xp7AppStatus.State.ERROR, error.get(), optionalAppInfo);
    }
    if (optionalDeployment.isEmpty()) {
        return setStatus(app, Xp7AppStatus.State.ERROR, "XP deployment not found", optionalAppInfo);
    }
    Xp7Deployment deployment = optionalDeployment.get();
    // Deployment is stopped
    if (!deployment.getSpec().getEnabled()) {
        return setStatus(app, Xp7AppStatus.State.STOPPED, "XP deployment stopped", optionalAppInfo);
    }
    // lets not change that until we have some app info
    if (notSuccessfullyInstalled().test(app) && optionalAppInfo.isEmpty() && app.getStatus().getState() == Xp7AppStatus.State.ERROR) {
        return false;
    }
    // No app info
    if (optionalAppInfo.isEmpty()) {
        return setStatus(app, Xp7AppStatus.State.PENDING, "Waiting for XP to start", optionalAppInfo);
    }
    AppInfo appInfo = optionalAppInfo.get();
    switch(appInfo.state()) {
        case "started":
            if (app.getSpec().getEnabled()) {
                return setStatus(app, Xp7AppStatus.State.RUNNING, "OK", optionalAppInfo);
            } else {
                return setStatus(app, Xp7AppStatus.State.PENDING, "Has not been stopped", optionalAppInfo);
            }
        case "stopped":
            if (app.getSpec().getEnabled()) {
                return setStatus(app, Xp7AppStatus.State.PENDING, "Has not been started", optionalAppInfo);
            } else {
                return setStatus(app, Xp7AppStatus.State.STOPPED, "OK", optionalAppInfo);
            }
        default:
            return setStatus(app, Xp7AppStatus.State.ERROR, String.format("Invalid app state '%s'", appInfo.state()), optionalAppInfo);
    }
}
Also used : Xp7Deployment(com.enonic.kubernetes.client.v1.xp7deployment.Xp7Deployment) Xp7App(com.enonic.kubernetes.client.v1.xp7app.Xp7App) AppInfo(com.enonic.kubernetes.apis.xp.service.AppInfo) Xp7AppStatusFieldsAppInfo(com.enonic.kubernetes.client.v1.xp7app.Xp7AppStatusFieldsAppInfo)

Aggregations

AppInfo (com.enonic.kubernetes.apis.xp.service.AppInfo)2 Xp7App (com.enonic.kubernetes.client.v1.xp7app.Xp7App)1 Xp7AppStatusFieldsAppInfo (com.enonic.kubernetes.client.v1.xp7app.Xp7AppStatusFieldsAppInfo)1 Xp7Deployment (com.enonic.kubernetes.client.v1.xp7deployment.Xp7Deployment)1