diff --git a/infrastructures/openshift/src/main/java/org/eclipse/che/workspace/infrastructure/openshift/OpenShiftInternalRuntime.java b/infrastructures/openshift/src/main/java/org/eclipse/che/workspace/infrastructure/openshift/OpenShiftInternalRuntime.java index 370bafe873..434ed889a1 100644 --- a/infrastructures/openshift/src/main/java/org/eclipse/che/workspace/infrastructure/openshift/OpenShiftInternalRuntime.java +++ b/infrastructures/openshift/src/main/java/org/eclipse/che/workspace/infrastructure/openshift/OpenShiftInternalRuntime.java @@ -24,12 +24,16 @@ import com.google.inject.assistedinject.Assisted; import org.eclipse.che.api.core.model.workspace.runtime.Machine; import org.eclipse.che.api.core.model.workspace.runtime.MachineStatus; +import org.eclipse.che.api.core.model.workspace.runtime.ServerStatus; import org.eclipse.che.api.core.notification.EventService; import org.eclipse.che.api.workspace.server.DtoConverter; import org.eclipse.che.api.workspace.server.URLRewriter; +import org.eclipse.che.api.workspace.server.hc.ServerCheckerFactory; +import org.eclipse.che.api.workspace.server.hc.ServersReadinessChecker; import org.eclipse.che.api.workspace.server.spi.InfrastructureException; import org.eclipse.che.api.workspace.server.spi.InternalRuntime; import org.eclipse.che.api.workspace.shared.dto.event.MachineStatusEvent; +import org.eclipse.che.api.workspace.shared.dto.event.ServerStatusEvent; import org.eclipse.che.dto.server.DtoFactory; import org.eclipse.che.workspace.infrastructure.openshift.bootstrapper.OpenShiftBootstrapperFactory; import org.slf4j.Logger; @@ -41,17 +45,20 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; +import java.util.function.Consumer; import static java.util.Collections.emptyMap; /** * @author Sergii Leshchenko + * @author Anton Korneta */ public class OpenShiftInternalRuntime extends InternalRuntime { private static final Logger LOG = LoggerFactory.getLogger(OpenShiftInternalRuntime.class); private final OpenShiftClientFactory clientFactory; private final EventService eventService; + private final ServerCheckerFactory serverCheckerFactory; private final OpenShiftBootstrapperFactory bootstrapperFactory; private final Map machines; private final int machineStartTimeoutMin; @@ -62,11 +69,13 @@ public class OpenShiftInternalRuntime extends InternalRuntime(); } @@ -113,23 +122,28 @@ public class OpenShiftInternalRuntime extends InternalRuntime stopOptions) throws InfrastructureException { LOG.info("Stopping workspace " + getContext().getIdentity().getWorkspaceId()); try { - cleanUpOpenshiftProject(getContext().getIdentity().getWorkspaceId()); + cleanUpOpenShiftProject(getContext().getIdentity().getWorkspaceId()); } catch (KubernetesClientException e) { //projects doesn't exist or is foreign LOG.info("Workspace {} was already stopped.", getContext().getIdentity().getWorkspaceId()); @@ -153,7 +167,7 @@ public class OpenShiftInternalRuntime extends InternalRuntime toDelete = new ArrayList<>(); toDelete.addAll(client.pods().inNamespace(projectName).list().getItems()); @@ -189,6 +203,30 @@ public class OpenShiftInternalRuntime extends InternalRuntime { + private String machineName; + + public ServerReadinessHandler(String machineName) { + this.machineName = machineName; + } + + @Override + public void accept(String serverRef) { + final OpenShiftMachine machine = machines.get(machineName); + if (machine == null) { + // Probably machine was removed from the list during server check start due to some reason + return; + } + // TODO set server status + eventService.publish(DtoFactory.newDto(ServerStatusEvent.class) + .withIdentity(DtoConverter.asDto(getContext().getIdentity())) + .withMachineName(machineName) + .withServerName(serverRef) + .withStatus(ServerStatus.RUNNING) + .withServerUrl(machine.getServers().get(serverRef).getUrl())); + } + } + @Override public Map getProperties() { return emptyMap(); diff --git a/infrastructures/openshift/src/main/java/org/eclipse/che/workspace/infrastructure/openshift/bootstrapper/OpenShiftBootstrapper.java b/infrastructures/openshift/src/main/java/org/eclipse/che/workspace/infrastructure/openshift/bootstrapper/OpenShiftBootstrapper.java index 5afffe0763..4ef3c325f4 100644 --- a/infrastructures/openshift/src/main/java/org/eclipse/che/workspace/infrastructure/openshift/bootstrapper/OpenShiftBootstrapper.java +++ b/infrastructures/openshift/src/main/java/org/eclipse/che/workspace/infrastructure/openshift/bootstrapper/OpenShiftBootstrapper.java @@ -43,7 +43,6 @@ public class OpenShiftBootstrapper extends AbstractBootstrapper { private static final String BOOTSTRAPPER_FILE = "bootstrapper"; private static final String CONFIG_FILE = "config.json"; - private final String machineName; private final RuntimeIdentity runtimeIdentity; private final List installers; private final int serverCheckPeriodSeconds; @@ -52,8 +51,7 @@ public class OpenShiftBootstrapper extends AbstractBootstrapper { private final String bootstrapperBinaryUrl; @Inject - public OpenShiftBootstrapper(@Assisted String machineName, - @Assisted RuntimeIdentity runtimeIdentity, + public OpenShiftBootstrapper(@Assisted RuntimeIdentity runtimeIdentity, @Assisted List installers, @Assisted OpenShiftMachine openShiftMachine, @Named("che.infra.openshift.che_server_websocket_endpoint_base") String websocketBaseEndpoint, @@ -62,9 +60,8 @@ public class OpenShiftBootstrapper extends AbstractBootstrapper { @Named("che.infra.openshift.bootstrapper.installer_timeout_sec") int installerTimeoutSeconds, @Named("che.infra.openshift.bootstrapper.server_check_period_sec") int serverCheckPeriodSeconds, EventService eventService) { - super(machineName, runtimeIdentity, bootstrappingTimeoutMinutes, websocketBaseEndpoint, eventService); + super(openShiftMachine.getName(), runtimeIdentity, bootstrappingTimeoutMinutes, websocketBaseEndpoint, eventService); this.bootstrapperBinaryUrl = bootstrapperBinaryUrl; - this.machineName = machineName; this.runtimeIdentity = runtimeIdentity; this.installers = installers; this.serverCheckPeriodSeconds = serverCheckPeriodSeconds; @@ -78,8 +75,9 @@ public class OpenShiftBootstrapper extends AbstractBootstrapper { injectBootstrapper(); openShiftMachine.exec("sh", "-c", BOOTSTRAPPER_DIR + BOOTSTRAPPER_FILE + - " -machine-name " + machineName + - " -runtime-id " + String.format("%s:%s:%s", runtimeIdentity.getWorkspaceId(), + " -machine-name " + openShiftMachine.getName() + + " -runtime-id " + String.format("%s:%s:%s", + runtimeIdentity.getWorkspaceId(), runtimeIdentity.getEnvName(), runtimeIdentity.getOwner()) + " -push-endpoint " + installerWebsocketEndpoint + diff --git a/infrastructures/openshift/src/main/java/org/eclipse/che/workspace/infrastructure/openshift/bootstrapper/OpenShiftBootstrapperFactory.java b/infrastructures/openshift/src/main/java/org/eclipse/che/workspace/infrastructure/openshift/bootstrapper/OpenShiftBootstrapperFactory.java index 138e91c0f9..407208d607 100644 --- a/infrastructures/openshift/src/main/java/org/eclipse/che/workspace/infrastructure/openshift/bootstrapper/OpenShiftBootstrapperFactory.java +++ b/infrastructures/openshift/src/main/java/org/eclipse/che/workspace/infrastructure/openshift/bootstrapper/OpenShiftBootstrapperFactory.java @@ -22,8 +22,7 @@ import java.util.List; * @author Sergii Leshchenko */ public interface OpenShiftBootstrapperFactory { - OpenShiftBootstrapper create(@Assisted String machineName, - @Assisted RuntimeIdentity runtimeIdentity, + OpenShiftBootstrapper create(@Assisted RuntimeIdentity runtimeIdentity, @Assisted List agents, @Assisted OpenShiftMachine openShiftMachine); }