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");
}
}
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);
}
}
Aggregations