Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make start of OpenShift machines parallel #8836

Merged
merged 1 commit into from
Feb 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -336,10 +336,13 @@ che.infra.kubernetes.trust_certs=
# Ignored for OpenShift infra. Use `che.infra.openshift.project` instead
che.infra.kubernetes.namespace=

che.infra.kubernetes.machine_start_timeout_min=5

# Defines time frame that limits the Kubernetes workspace start time
che.infra.kubernetes.workspace_start_timeout_min=8
# Defines the timeout in minutes that limits the period for which Kubernetes Ingress become ready
che.infra.kubernetes.ingress_start_timeout_min=5

che.infra.kubernetes.bootstrapper.binary_url=http://${CHE_HOST}:${CHE_PORT}/agent-binaries/linux_amd64/bootstrapper/bootstrapper
che.infra.kubernetes.bootstrapper.timeout_min=10
che.infra.kubernetes.bootstrapper.installer_timeout_sec=180
che.infra.kubernetes.bootstrapper.server_check_period_sec=3

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ che.infra.kubernetes.username=che.infra.openshift.username
che.infra.kubernetes.password=che.infra.openshift.password
che.infra.kubernetes.oauth_token=che.infra.openshift.oauth_token
che.infra.kubernetes.trust_certs=che.infra.openshift.trust_certs
che.infra.kubernetes.machine_start_timeout_min=che.infra.openshift.machine_start_timeout_min
che.infra.kubernetes.bootstrapper.binary_url=che.infra.openshift.bootstrapper.binary_url
che.infra.kubernetes.bootstrapper.timeout_min=che.infra.openshift.bootstrapper.timeout_min
che.infra.kubernetes.bootstrapper.installer_timeout_sec=che.infra.openshift.bootstrapper.installer_timeout_sec
che.infra.kubernetes.bootstrapper.server_check_period_sec=che.infra.openshift.bootstrapper.server_check_period_sec
che.infra.kubernetes.pvc.enabled=che.infra.openshift.pvc.enabled
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.List;
import java.util.Map;
import java.util.function.Consumer;
import javax.inject.Named;
import org.eclipse.che.api.core.model.workspace.Warning;
import org.eclipse.che.api.core.model.workspace.runtime.Machine;
import org.eclipse.che.api.core.model.workspace.runtime.MachineStatus;
Expand Down Expand Up @@ -77,6 +78,7 @@ public class DockerInternalRuntime extends InternalRuntime<DockerRuntimeContext>
private final ProbeScheduler probeScheduler;
private final WorkspaceProbesFactory probesFactory;
private final ParallelDockerImagesBuilderFactory imagesBuilderFactory;
private final int bootstrappingTimeoutMinutes;

/**
* Creates non running runtime. Normally created by {@link
Expand All @@ -95,7 +97,8 @@ public DockerInternalRuntime(
MachineLoggersFactory loggers,
ProbeScheduler probeScheduler,
WorkspaceProbesFactory probesFactory,
ParallelDockerImagesBuilderFactory imagesBuilderFactory) {
ParallelDockerImagesBuilderFactory imagesBuilderFactory,
@Named("che.infra.docker.bootstrapper.timeout_min") int bootstrappingTimeoutMinutes) {
this(
context,
urlRewriter,
Expand All @@ -109,7 +112,8 @@ public DockerInternalRuntime(
loggers,
probeScheduler,
probesFactory,
imagesBuilderFactory);
imagesBuilderFactory,
bootstrappingTimeoutMinutes);
}

/**
Expand All @@ -132,7 +136,8 @@ public DockerInternalRuntime(
DockerMachineStopDetector stopDetector,
ProbeScheduler probeScheduler,
WorkspaceProbesFactory probesFactory,
ParallelDockerImagesBuilderFactory imagesBuilderFactory)
ParallelDockerImagesBuilderFactory imagesBuilderFactory,
@Named("che.infra.docker.bootstrapper.timeout_min") int bootstrappingTimeoutMinutes)
throws InfrastructureException {
this(
context,
Expand All @@ -147,7 +152,8 @@ public DockerInternalRuntime(
loggers,
probeScheduler,
probesFactory,
imagesBuilderFactory);
imagesBuilderFactory,
bootstrappingTimeoutMinutes);

for (ContainerListEntry container : containers) {
DockerMachine machine = machineCreator.create(container);
Expand All @@ -172,14 +178,16 @@ private DockerInternalRuntime(
MachineLoggersFactory loggers,
ProbeScheduler probeScheduler,
WorkspaceProbesFactory probesFactory,
ParallelDockerImagesBuilderFactory imagesBuilderFactory) {
ParallelDockerImagesBuilderFactory imagesBuilderFactory,
int bootstrappingTimeoutMinutes) {
super(context, urlRewriter, warnings, running);
this.networks = networks;
this.containerStarter = machineStarter;
this.eventService = eventService;
this.bootstrapperFactory = bootstrapperFactory;
this.serverCheckerFactory = serverCheckerFactory;
this.probesFactory = probesFactory;
this.bootstrappingTimeoutMinutes = bootstrappingTimeoutMinutes;
this.properties = new HashMap<>();
this.startSynchronizer = new StartSynchronizer();
this.runtimeMachines = new RuntimeMachines();
Expand Down Expand Up @@ -290,13 +298,12 @@ void checkServers() throws InfrastructureException {
runtimeMachines.getMachines().entrySet()) {
String name = entry.getKey();
DockerMachine machine = entry.getValue();
ServersChecker checker =
serverCheckerFactory.create(getContext().getIdentity(), name, machine.getServers());
RuntimeIdentity runtimeId = getContext().getIdentity();
ServersChecker checker = serverCheckerFactory.create(runtimeId, name, machine.getServers());
checker.checkOnce(new ServerReadinessHandler(name));

probeScheduler.schedule(
probesFactory.getProbes(
getContext().getIdentity().getWorkspaceId(), name, machine.getServers()),
probesFactory.getProbes(runtimeId, name, machine.getServers()),
new ServerLivenessHandler());
}
}
Expand Down Expand Up @@ -340,8 +347,7 @@ private void checkServers(String name, DockerMachine machine)
checkInterruption();
// continuous checking
probeScheduler.schedule(
probesFactory.getProbes(identity.getWorkspaceId(), name, machine.getServers()),
new ServerLivenessHandler());
probesFactory.getProbes(identity, name, machine.getServers()), new ServerLivenessHandler());
}

private void bootstrapInstallers(String name, DockerMachine machine)
Expand All @@ -351,7 +357,9 @@ private void bootstrapInstallers(String name, DockerMachine machine)

if (!machineCfg.getInstallers().isEmpty()) {
checkInterruption();
bootstrapperFactory.create(name, identity, machineCfg.getInstallers(), machine).bootstrap();
bootstrapperFactory
.create(name, identity, machineCfg.getInstallers(), machine)
.bootstrap(bootstrappingTimeoutMinutes);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,7 @@ public DockerBootstrapper(
@Named("che.infra.docker.bootstrapper.installer_timeout_sec") int installerTimeoutSeconds,
@Named("che.infra.docker.bootstrapper.server_check_period_sec")
int serverCheckPeriodSeconds) {
super(
machineName,
runtimeIdentity,
bootstrappingTimeoutMinutes,
cheWebsocketEndpoint,
cheWebsocketEndpoint,
eventService);
super(machineName, runtimeIdentity, cheWebsocketEndpoint, cheWebsocketEndpoint, eventService);
this.machineName = machineName;
this.runtimeIdentity = runtimeIdentity;
this.dockerMachine = dockerMachine;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ public class DockerInternalRuntimeTest {
private static final String SERVER_1 = "serv1";
private static final String SERVER_URL = "https://localhost:443/path";

private static final int BOOTSTRAPPING_TIMEOUT_MINUTES = 5;

@Mock private DockerBootstrapperFactory bootstrapperFactory;
@Mock private DockerRuntimeContext runtimeContext;
@Mock private EventService eventService;
Expand Down Expand Up @@ -135,7 +137,7 @@ public void setup() throws Exception {
ServersCheckerFactory serversCheckerFactory = mock(ServersCheckerFactory.class);
when(serversCheckerFactory.create(any(), nullable(String.class), any()))
.thenReturn(mock(ServersChecker.class));
when(workspaceProbesFactory.getProbes(eq(IDENTITY.getWorkspaceId()), anyString(), any()))
when(workspaceProbesFactory.getProbes(eq(IDENTITY), anyString(), any()))
.thenReturn(workspaceProbes);
when(dockerImagesBuilderFactory.create(any())).thenReturn(dockerImagesBuilder);
when(dockerImagesBuilder.prepareImages(anyMap())).thenReturn(emptyMap());
Expand All @@ -152,7 +154,8 @@ public void setup() throws Exception {
mock(MachineLoggersFactory.class),
probesScheduler,
workspaceProbesFactory,
dockerImagesBuilderFactory);
dockerImagesBuilderFactory,
BOOTSTRAPPING_TIMEOUT_MINUTES);
}

@Test
Expand Down Expand Up @@ -218,7 +221,7 @@ public void throwsExceptionWhenBootstrappingOfInstallersFailed() throws Exceptio
any(),
any(),
any());
verify(bootstrapper, times(1)).bootstrap();
verify(bootstrapper, times(1)).bootstrap(BOOTSTRAPPING_TIMEOUT_MINUTES);
verify(eventService, times(4)).publish(any(MachineStatusEvent.class));
verifyEventsOrder(
newEvent(DEV_MACHINE, STARTING, null),
Expand Down Expand Up @@ -342,9 +345,9 @@ public void schedulesProbesOnMachineStart() throws Exception {
mockContainerStart();
WorkspaceProbes m1Probes = mock(WorkspaceProbes.class);
WorkspaceProbes m2Probes = mock(WorkspaceProbes.class);
when(workspaceProbesFactory.getProbes(eq(IDENTITY.getWorkspaceId()), eq(DB_MACHINE), any()))
when(workspaceProbesFactory.getProbes(eq(IDENTITY), eq(DB_MACHINE), anyMap()))
.thenReturn(m1Probes);
when(workspaceProbesFactory.getProbes(eq(IDENTITY.getWorkspaceId()), eq(DEV_MACHINE), any()))
when(workspaceProbesFactory.getProbes(eq(IDENTITY), eq(DEV_MACHINE), any()))
.thenReturn(m2Probes);

dockerRuntime.start(emptyMap());
Expand All @@ -368,7 +371,7 @@ public void updatesServerStatusOnProbeResult(
mockInstallersBootstrap();
mockContainerStart();
WorkspaceProbes m1Probes = mock(WorkspaceProbes.class);
when(workspaceProbesFactory.getProbes(eq(IDENTITY.getWorkspaceId()), eq(DB_MACHINE), any()))
when(workspaceProbesFactory.getProbes(eq(IDENTITY), eq(DB_MACHINE), any()))
.thenReturn(m1Probes);
dockerRuntime.start(emptyMap());
verify(probesScheduler).schedule(eq(m1Probes), probeResultConsumerCaptor.capture());
Expand Down Expand Up @@ -457,7 +460,7 @@ private void mockInstallersBootstrap() throws Exception {
anyList(),
nullable(DockerMachine.class)))
.thenReturn(bootstrapper);
doNothing().when(bootstrapper).bootstrap();
doNothing().when(bootstrapper).bootstrap(BOOTSTRAPPING_TIMEOUT_MINUTES);
}

private void mockInstallersBootstrapFailed(InfrastructureException exception) throws Exception {
Expand All @@ -467,7 +470,7 @@ private void mockInstallersBootstrapFailed(InfrastructureException exception) th
anyList(),
nullable(DockerMachine.class)))
.thenReturn(bootstrapper);
doThrow(exception).when(bootstrapper).bootstrap();
doThrow(exception).when(bootstrapper).bootstrap(BOOTSTRAPPING_TIMEOUT_MINUTES);
}

private InstallerImpl newInstaller(int i) {
Expand Down
Loading