Skip to content

Commit

Permalink
Introduced two web-socket endpoints for workspace master to split JSO…
Browse files Browse the repository at this point in the history
…N-RPC messages (#12673)

* Introduced two web-socket endpoints for workspace master to split JSON-RPC messages
Based on Dmytro's Kulieshov  work #12252

Signed-off-by: Sergii Kabashniuk <[email protected]>
  • Loading branch information
skabashnyuk authored Feb 27, 2019
1 parent 3778f01 commit a5b06d4
Show file tree
Hide file tree
Showing 35 changed files with 1,027 additions and 87 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
/*
* Copyright (c) 2012-2018 Red Hat, Inc.
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Red Hat, Inc. - initial API and implementation
*/
package org.eclipse.che.api.deploy;

import com.google.inject.Binder;
import com.google.inject.Module;
import io.micrometer.core.instrument.Tags;
import io.micrometer.prometheus.PrometheusMeterRegistry;
import java.util.concurrent.ExecutorService;
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
import org.eclipse.che.api.deploy.jsonrpc.CheMajorWebSocketEndpointConfiguration;
import org.eclipse.che.api.deploy.jsonrpc.CheMajorWebSocketEndpointExecutorServiceProvider;
import org.eclipse.che.api.deploy.jsonrpc.CheMinorWebSocketEndpointConfiguration;
import org.eclipse.che.api.deploy.jsonrpc.CheMinorWebSocketEndpointExecutorServiceProvider;
import org.eclipse.che.core.metrics.ExecutorServiceMetrics;

/**
* {@link Module} that provides metered implementation for different classes. Metrics will be
* published to {@link PrometheusMeterRegistry}.
*/
public class MetricsOverrideBinding implements Module {
@Override
public void configure(Binder binder) {
binder
.bind(CheMajorWebSocketEndpointExecutorServiceProvider.class)
.to(MeteredCheMajorWebSocketEndpointExecutorServiceProvider.class);

binder
.bind(CheMinorWebSocketEndpointExecutorServiceProvider.class)
.to(MeteredCheMinorWebSocketEndpointExecutorServiceProvider.class);
}

@Singleton
public static class MeteredCheMajorWebSocketEndpointExecutorServiceProvider
extends CheMajorWebSocketEndpointExecutorServiceProvider {

private final PrometheusMeterRegistry meterRegistry;

private ExecutorService executorService;

@Inject
public MeteredCheMajorWebSocketEndpointExecutorServiceProvider(
@Named(JSON_RPC_MAJOR_CORE_POOL_SIZE_PARAMETER_NAME) int corePoolSize,
@Named(JSON_RPC_MAJOR_MAX_POOL_SIZE_PARAMETER_NAME) int maxPoolSize,
@Named(JSON_RPC_MAJOR_QUEUE_CAPACITY_PARAMETER_NAME) int queueCapacity,
PrometheusMeterRegistry meterRegistry) {
super(corePoolSize, maxPoolSize, queueCapacity);
this.meterRegistry = meterRegistry;
}

@Override
public synchronized ExecutorService get() {
if (executorService == null) {
executorService =
ExecutorServiceMetrics.monitor(
meterRegistry,
super.get(),
CheMajorWebSocketEndpointConfiguration.EXECUTOR_NAME,
Tags.empty());
}
return executorService;
}
}

@Singleton
public static class MeteredCheMinorWebSocketEndpointExecutorServiceProvider
extends CheMinorWebSocketEndpointExecutorServiceProvider {
private final PrometheusMeterRegistry meterRegistry;

private ExecutorService executorService;

@Inject
public MeteredCheMinorWebSocketEndpointExecutorServiceProvider(
@Named(JSON_RPC_MINOR_CORE_POOL_SIZE_PARAMETER_NAME) int corePoolSize,
@Named(JSON_RPC_MINOR_MAX_POOL_SIZE_PARAMETER_NAME) int maxPoolSize,
@Named(JSON_RPC_MINOR_QUEUE_CAPACITY_PARAMETER_NAME) int queueCapacity,
PrometheusMeterRegistry meterRegistry) {
super(corePoolSize, maxPoolSize, queueCapacity);
this.meterRegistry = meterRegistry;
}

@Override
public synchronized ExecutorService get() {
if (executorService == null) {

executorService =
ExecutorServiceMetrics.monitor(
meterRegistry,
super.get(),
CheMinorWebSocketEndpointConfiguration.EXECUTOR_NAME,
Tags.empty());
}
return executorService;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.eclipse.che.api.core.rest.CheJsonProvider;
import org.eclipse.che.api.core.rest.MessageBodyAdapter;
import org.eclipse.che.api.core.rest.MessageBodyAdapterInterceptor;
import org.eclipse.che.api.deploy.jsonrpc.CheJsonRpcWebSocketConfigurationModule;
import org.eclipse.che.api.devfile.server.DevfileModule;
import org.eclipse.che.api.factory.server.FactoryAcceptValidator;
import org.eclipse.che.api.factory.server.FactoryCreateValidator;
Expand Down Expand Up @@ -279,6 +280,7 @@ protected void configure() {
install(new LocalDockerModule());
install(new DockerInfraModule());
}
install(new CheJsonRpcWebSocketConfigurationModule());

bind(org.eclipse.che.api.user.server.AppStatesPreferenceCleaner.class);
MapBinder.newMapBinder(binder(), String.class, ChePluginsApplier.class);
Expand All @@ -289,6 +291,7 @@ protected void configure() {
if (Boolean.valueOf(System.getenv("CHE_METRICS_ENABLED"))) {
install(new org.eclipse.che.core.metrics.MetricsModule());
install(new WsMasterMetricsModule());
install(new MetricsOverrideBinding());
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright (c) 2012-2018 Red Hat, Inc.
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Red Hat, Inc. - initial API and implementation
*/
package org.eclipse.che.api.deploy.jsonrpc;

import com.google.inject.Binder;
import com.google.inject.Module;
import com.google.inject.multibindings.Multibinder;
import com.google.inject.name.Names;
import java.util.concurrent.ExecutorService;
import org.eclipse.che.api.core.jsonrpc.commons.RequestProcessorConfigurationProvider;

/** Configures JSON RPC WebSocket Endpoints. */
public class CheJsonRpcWebSocketConfigurationModule implements Module {
@Override
public void configure(Binder binder) {
binder
.bind(ExecutorService.class)
.annotatedWith(Names.named(CheMajorWebSocketEndpointConfiguration.EXECUTOR_NAME))
.toProvider(CheMajorWebSocketEndpointExecutorServiceProvider.class);

binder
.bind(ExecutorService.class)
.annotatedWith(Names.named(CheMinorWebSocketEndpointConfiguration.EXECUTOR_NAME))
.toProvider(CheMinorWebSocketEndpointExecutorServiceProvider.class);

Multibinder<RequestProcessorConfigurationProvider.Configuration> configurationMultibinder =
Multibinder.newSetBinder(binder, RequestProcessorConfigurationProvider.Configuration.class);
configurationMultibinder.addBinding().to(CheMajorWebSocketEndpointConfiguration.class);
configurationMultibinder.addBinding().to(CheMinorWebSocketEndpointConfiguration.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* Contributors:
* Red Hat, Inc. - initial API and implementation
*/
package org.eclipse.che.api.deploy;
package org.eclipse.che.api.deploy.jsonrpc;

import javax.inject.Inject;
import javax.websocket.server.ServerEndpoint;
Expand All @@ -25,9 +25,12 @@
* "/websocket".
*/
@ServerEndpoint(value = "/websocket", configurator = GuiceInjectorEndpointConfigurator.class)
public class CheWebSocketEndpoint extends BasicWebSocketEndpoint {
public class CheMajorWebSocketEndpoint extends BasicWebSocketEndpoint {

public static final String ENDPOINT_ID = "master-websocket-major-endpoint";

@Inject
public CheWebSocketEndpoint(
public CheMajorWebSocketEndpoint(
WebSocketSessionRegistry registry,
MessagesReSender reSender,
WebSocketMessageReceiver receiver,
Expand All @@ -37,6 +40,6 @@ public CheWebSocketEndpoint(

@Override
protected String getEndpointId() {
return "master-websocket-endpoint";
return ENDPOINT_ID;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright (c) 2012-2018 Red Hat, Inc.
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Red Hat, Inc. - initial API and implementation
*/
package org.eclipse.che.api.deploy.jsonrpc;

import java.util.concurrent.ExecutorService;
import javax.inject.Inject;
import javax.inject.Named;
import org.eclipse.che.api.core.jsonrpc.commons.RequestProcessorConfigurationProvider;

/**
* {@link RequestProcessorConfigurationProvider.Configuration} implementation used to configure
* {@link CheMajorWebSocketEndpoint}
*/
public class CheMajorWebSocketEndpointConfiguration
implements RequestProcessorConfigurationProvider.Configuration {

private final ExecutorService executor;

public static final String EXECUTOR_NAME = "che.core.jsonrpc.major_executor";

@Inject
public CheMajorWebSocketEndpointConfiguration(@Named(EXECUTOR_NAME) ExecutorService executor) {
this.executor = executor;
}

@Override
public String getEndpointId() {
return CheMajorWebSocketEndpoint.ENDPOINT_ID;
}

@Override
public ExecutorService getExecutorService() {
return executor;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright (c) 2012-2018 Red Hat, Inc.
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Red Hat, Inc. - initial API and implementation
*/
package org.eclipse.che.api.deploy.jsonrpc;

import java.util.concurrent.ExecutorService;
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
import org.eclipse.che.commons.lang.execution.ExecutorServiceProvider;

/** {@link ExecutorService} provider used in {@link CheMajorWebSocketEndpoint}. */
@Singleton
public class CheMajorWebSocketEndpointExecutorServiceProvider extends ExecutorServiceProvider {

public static final String JSON_RPC_MAJOR_CORE_POOL_SIZE_PARAMETER_NAME =
"che.core.jsonrpc.processor_core_pool_size";
public static final String JSON_RPC_MAJOR_MAX_POOL_SIZE_PARAMETER_NAME =
"che.core.jsonrpc.processor_max_pool_size";
public static final String JSON_RPC_MAJOR_QUEUE_CAPACITY_PARAMETER_NAME =
"che.core.jsonrpc.processor_queue_capacity";

@Inject
public CheMajorWebSocketEndpointExecutorServiceProvider(
@Named(JSON_RPC_MAJOR_CORE_POOL_SIZE_PARAMETER_NAME) int corePoolSize,
@Named(JSON_RPC_MAJOR_MAX_POOL_SIZE_PARAMETER_NAME) int maxPoolSize,
@Named(JSON_RPC_MAJOR_QUEUE_CAPACITY_PARAMETER_NAME) int queueCapacity) {
super(corePoolSize, maxPoolSize, queueCapacity);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* Contributors:
* Red Hat, Inc. - initial API and implementation
*/
package org.eclipse.che.wsagent.server;
package org.eclipse.che.api.deploy.jsonrpc;

import javax.inject.Inject;
import javax.websocket.server.ServerEndpoint;
Expand All @@ -21,15 +21,16 @@
import org.eclipse.che.api.core.websocket.impl.WebsocketIdService;

/**
* Implementation of BasicWebSocketEndpoint for Che packaging. Add only mapping "/wsagent".
*
* @author Vitalii Parfonov
* Implementation of {@link BasicWebSocketEndpoint} for Che packaging. Add only mapping
* "/websocket-minor".
*/
@ServerEndpoint(value = "/wsagent", configurator = GuiceInjectorEndpointConfigurator.class)
public class CheWebSocketEndpoint extends BasicWebSocketEndpoint {
@ServerEndpoint(value = "/websocket-minor", configurator = GuiceInjectorEndpointConfigurator.class)
public class CheMinorWebSocketEndpoint extends BasicWebSocketEndpoint {

public static final String ENDPOINT_ID = "master-websocket-minor-endpoint";

@Inject
public CheWebSocketEndpoint(
public CheMinorWebSocketEndpoint(
WebSocketSessionRegistry registry,
MessagesReSender reSender,
WebSocketMessageReceiver receiver,
Expand All @@ -39,6 +40,6 @@ public CheWebSocketEndpoint(

@Override
protected String getEndpointId() {
return "ws-agent-websocket-endpoint";
return ENDPOINT_ID;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright (c) 2012-2018 Red Hat, Inc.
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Red Hat, Inc. - initial API and implementation
*/
package org.eclipse.che.api.deploy.jsonrpc;

import java.util.concurrent.ExecutorService;
import javax.inject.Inject;
import javax.inject.Named;
import org.eclipse.che.api.core.jsonrpc.commons.RequestProcessorConfigurationProvider;

/**
* {@link RequestProcessorConfigurationProvider.Configuration} implementation used to configure
* {@link CheMinorWebSocketEndpoint}
*/
public class CheMinorWebSocketEndpointConfiguration
implements RequestProcessorConfigurationProvider.Configuration {

private final ExecutorService executor;

public static final String EXECUTOR_NAME = "che.core.jsonrpc.minor_executor";

@Inject
public CheMinorWebSocketEndpointConfiguration(@Named(EXECUTOR_NAME) ExecutorService executor) {
this.executor = executor;
}

@Override
public String getEndpointId() {
return CheMinorWebSocketEndpoint.ENDPOINT_ID;
}

@Override
public ExecutorService getExecutorService() {
return executor;
}
}
Loading

0 comments on commit a5b06d4

Please sign in to comment.