use of org.eclipse.che.api.workspace.server.spi.InternalInfrastructureException in project che-server by eclipse-che.
the class PassThroughProxyProvisioner method constructSignatureKeyPair.
/**
* Constructs a key pair to satisfy JWT proxy which needs a key pair in its configuration. In case
* of pass-through proxy, this key pair is unused so we just generate a random one.
*
* @return a random key pair
* @throws InternalInfrastructureException if RSA is not available as a key pair generator. This
* should not happen.
*/
private static KeyPair constructSignatureKeyPair() throws InternalInfrastructureException {
try {
KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA");
kpg.initialize(512);
return kpg.generateKeyPair();
} catch (NoSuchAlgorithmException e) {
throw new InternalInfrastructureException("Could not generate a fake key pair to support JWT proxy in single-user mode.");
}
}
use of org.eclipse.che.api.workspace.server.spi.InternalInfrastructureException in project che-server by eclipse-che.
the class PreviewUrlExposer method expose.
public void expose(T env) throws InternalInfrastructureException {
List<CommandImpl> previewUrlCommands = env.getCommands().stream().filter(c -> c.getPreviewUrl() != null).collect(Collectors.toList());
List<ServicePort> portsToProvision = new ArrayList<>();
for (CommandImpl command : previewUrlCommands) {
int port = command.getPreviewUrl().getPort();
Optional<Service> foundService = Services.findServiceWithPort(env.getServices().values(), port);
if (foundService.isPresent()) {
if (!hasMatchingEndpoint(env, foundService.get(), port)) {
ServicePort servicePort = Services.findPort(foundService.get(), port).orElseThrow(() -> new InternalInfrastructureException(String.format("Port '%d' in service '%s' not found. This is not expected, please report a bug!", port, foundService.get().getMetadata().getName())));
String serviceName = foundService.get().getMetadata().getName();
externalServerExposer.expose(env, null, serviceName, serviceName, servicePort, Collections.emptyMap());
}
} else {
portsToProvision.add(createServicePort(port));
}
}
if (!portsToProvision.isEmpty()) {
String serverName = generate(SERVER_PREFIX, SERVER_UNIQUE_PART_SIZE) + "-previewUrl";
Service service = new ServerServiceBuilder().withName(serverName).withPorts(portsToProvision).build();
env.getServices().put(serverName, service);
portsToProvision.forEach(port -> externalServerExposer.expose(env, null, service.getMetadata().getName(), service.getMetadata().getName(), port, Collections.emptyMap()));
}
}
use of org.eclipse.che.api.workspace.server.spi.InternalInfrastructureException in project che-server by eclipse-che.
the class WsAgentServerLivenessProbeConfigFactory method get.
@Override
public HttpProbeConfig get(String userId, String workspaceId, Server server) throws InternalInfrastructureException {
try {
// add check path
URI uri = UriBuilder.fromUri(server.getUrl()).path("/liveness").build();
int port;
if (uri.getPort() == -1) {
if ("http".equals(uri.getScheme())) {
port = 80;
} else {
port = 443;
}
} else {
port = uri.getPort();
}
return new HttpProbeConfig(port, uri.getHost(), uri.getScheme(), uri.getPath(), singletonMap(HttpHeaders.AUTHORIZATION, "Bearer " + machineTokenProvider.getToken(userId, workspaceId)), successThreshold, 3, 120, 10, 10);
} catch (MachineTokenException e) {
throw new InternalInfrastructureException("Failed to retrieve workspace token for ws-agent server liveness probe. Error: " + e.getMessage());
} catch (UriBuilderException e) {
throw new InternalInfrastructureException("Wsagent server liveness probe url is invalid. Error: " + e.getMessage());
}
}
use of org.eclipse.che.api.workspace.server.spi.InternalInfrastructureException in project che-server by eclipse-che.
the class ServersChecker method startAsync.
/**
* Asynchronously starts checking readiness of servers of a machine. Method {@link #await()} waits
* the result of this asynchronous check.
*
* @param serverReadinessHandler consumer which will be called with server reference as the
* argument when server become available
* @throws InternalInfrastructureException if check of a server failed due to an unexpected error
* @throws InfrastructureException if check of a server failed due to an error
*/
public CompletableFuture<?> startAsync(Consumer<String> serverReadinessHandler) throws InfrastructureException {
timer = new Timer("ServersChecker", true);
List<ServerChecker> serverCheckers = getServerCheckers();
// should be completed with an exception if a server considered unavailable
CompletableFuture<Void> firstNonAvailable = new CompletableFuture<>();
CompletableFuture[] checkTasks = serverCheckers.stream().map(ServerChecker::getReportCompFuture).map(compFut -> compFut.thenAccept(serverReadinessHandler).exceptionally(e -> {
// cleanup checkers tasks
timer.cancel();
firstNonAvailable.completeExceptionally(e);
return null;
})).toArray(CompletableFuture[]::new);
resultTimeoutSeconds = checkTasks.length * 180;
// should complete when all servers checks reported availability
CompletableFuture<Void> allAvailable = CompletableFuture.allOf(checkTasks);
// should complete when all servers are available or any server is unavailable
result = CompletableFuture.anyOf(allAvailable, firstNonAvailable);
for (ServerChecker serverChecker : serverCheckers) {
serverChecker.start();
}
return result;
}
use of org.eclipse.che.api.workspace.server.spi.InternalInfrastructureException in project che-server by eclipse-che.
the class StartSynchronizerTest method shouldWrapExceptionIntoInternalExcWhenItIsCompletedWithNonInfraException.
@Test
public void shouldWrapExceptionIntoInternalExcWhenItIsCompletedWithNonInfraException() {
// given
RuntimeException toThrow = new RuntimeException("test exception");
startSynchronizer.completeExceptionally(toThrow);
// when
InfrastructureException startFailure = startSynchronizer.getStartFailureNow();
// then
assertTrue(startFailure instanceof InternalInfrastructureException);
assertEquals(startFailure.getCause(), toThrow);
}
Aggregations