CHE-730. Fix problems related to refusing WebSocket connection when machine is restarted
Signed-off-by: Roman Nikitenko <rnikitenko@codenvy.com>6.19.x
parent
b618d6994b
commit
73ad9f56a3
|
|
@ -139,6 +139,13 @@ abstract class AbstractMessageBus implements MessageBus {
|
|||
};
|
||||
}
|
||||
|
||||
public void cancelReconnection() {
|
||||
frequentlyReconnectionAttemptsCounter = MAX_FREQUENTLY_RECONNECTION_ATTEMPTS;
|
||||
seldomReconnectionAttemptsCounter = MAX_SELDOM_RECONNECTION_ATTEMPTS;
|
||||
frequentlyReconnectionTimer.cancel();
|
||||
seldomReconnectionTimer.cancel();
|
||||
}
|
||||
|
||||
private void initialize() {
|
||||
ws = WebSocket.create(wsConnectionUrl);
|
||||
wsListener = new WsListener();
|
||||
|
|
@ -329,7 +336,6 @@ abstract class AbstractMessageBus implements MessageBus {
|
|||
* e.g.: WebSocket is not supported by browser, WebSocket connection is not opened
|
||||
*/
|
||||
private void send(String message) throws WebSocketException {
|
||||
// checkWebSocketConnectionState();
|
||||
if (getReadyState() != ReadyState.OPEN) {
|
||||
messages2send.add(message);
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -183,4 +183,9 @@ public interface MessageBus extends MessageReceivedHandler {
|
|||
* @return <code>true</code> if handler subscribed to channel and <code>false</code> if not
|
||||
*/
|
||||
boolean isHandlerSubscribed(MessageHandler handler, String channel);
|
||||
}
|
||||
|
||||
/**
|
||||
* Cancels attempts to reconnect by WebSocket
|
||||
*/
|
||||
void cancelReconnection();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -182,6 +182,9 @@ public abstract class WorkspaceComponent implements Component, WsAgentStateHandl
|
|||
loader.show(initialLoadingInfo);
|
||||
initialLoadingInfo.setOperationStatus(WORKSPACE_BOOTING.getValue(), IN_PROGRESS);
|
||||
|
||||
if (messageBus != null) {
|
||||
messageBus.cancelReconnection();
|
||||
}
|
||||
messageBus = messageBusProvider.createMessageBus(workspace.getId());
|
||||
|
||||
messageBus.addOnOpenHandler(new ConnectionOpenedHandler() {
|
||||
|
|
|
|||
|
|
@ -26,6 +26,14 @@ public interface MachineManager {
|
|||
START, RESTART, DESTROY
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs some actions when dev machine is creating.
|
||||
*
|
||||
* @param machineConfig
|
||||
* contains information about dev machine configuration
|
||||
*/
|
||||
void onDevMachineCreating(MachineConfigDto machineConfig);
|
||||
|
||||
/**
|
||||
* Performs some actions when machine is running.
|
||||
*
|
||||
|
|
@ -72,10 +80,12 @@ public interface MachineManager {
|
|||
void restartMachine(final MachineDto machine);
|
||||
|
||||
/**
|
||||
* Performs some actions when dev machine is creating.
|
||||
* Checks if the the status for dev machine is tracked by machine manager.
|
||||
*
|
||||
* @param machineConfig
|
||||
* contains information about dev machine configuration
|
||||
* @param machine
|
||||
* contains information about machine state
|
||||
* @return {@code true} if status for dev machine is tracked by machine manager and {@code false} - otherwise.
|
||||
*/
|
||||
void onDevMachineCreating(MachineConfigDto machineConfig);
|
||||
boolean isDevMachineStatusTracked(MachineDto machine);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -201,10 +201,13 @@ public class WsAgentStateController implements ConnectionOpenedHandler, Connecti
|
|||
* Try to connect via WebSocket connection
|
||||
*/
|
||||
private void checkWsConnection() {
|
||||
if (messageBus != null) {
|
||||
messageBus.cancelReconnection();
|
||||
}
|
||||
messageBus = messageBusProvider.createMachineMessageBus(wsUrl);
|
||||
|
||||
messageBus.addOnCloseHandler(this);
|
||||
messageBus.addOnCloseHandler(this);
|
||||
messageBus.addOnOpenHandler(this);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -62,9 +62,11 @@ public class MachineComponent implements WsAgentComponent {
|
|||
|
||||
if (isDev && status == RUNNING) {
|
||||
callback.onSuccess(MachineComponent.this);
|
||||
|
||||
appContext.setDevMachineId(descriptor.getId());
|
||||
machineManager.onMachineRunning(descriptor.getId());
|
||||
|
||||
if (!machineManager.isDevMachineStatusTracked(descriptor)) {
|
||||
machineManager.onMachineRunning(descriptor.getId());
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (isDev && status == CREATING) {
|
||||
|
|
|
|||
|
|
@ -15,13 +15,12 @@ import com.google.inject.Singleton;
|
|||
import com.google.web.bindery.event.shared.EventBus;
|
||||
|
||||
import org.eclipse.che.api.core.rest.shared.dto.LinkParameter;
|
||||
import org.eclipse.che.api.machine.gwt.client.WsAgentStateController;
|
||||
import org.eclipse.che.api.machine.gwt.client.MachineManager;
|
||||
import org.eclipse.che.api.machine.gwt.client.MachineServiceClient;
|
||||
import org.eclipse.che.api.machine.gwt.client.OutputMessageUnmarshaller;
|
||||
import org.eclipse.che.api.machine.gwt.client.WsAgentStateController;
|
||||
import org.eclipse.che.api.machine.gwt.client.events.DevMachineStateEvent;
|
||||
import org.eclipse.che.api.machine.gwt.client.events.MachineStartingEvent;
|
||||
import org.eclipse.che.api.machine.shared.Constants;
|
||||
import org.eclipse.che.api.machine.shared.dto.LimitsDto;
|
||||
import org.eclipse.che.api.machine.shared.dto.MachineConfigDto;
|
||||
import org.eclipse.che.api.machine.shared.dto.MachineDto;
|
||||
|
|
@ -53,6 +52,8 @@ import org.eclipse.che.ide.websocket.rest.Unmarshallable;
|
|||
import static org.eclipse.che.api.machine.gwt.client.MachineManager.MachineOperationType.DESTROY;
|
||||
import static org.eclipse.che.api.machine.gwt.client.MachineManager.MachineOperationType.RESTART;
|
||||
import static org.eclipse.che.api.machine.gwt.client.MachineManager.MachineOperationType.START;
|
||||
import static org.eclipse.che.api.machine.shared.Constants.LINK_REL_GET_MACHINE_LOGS_CHANNEL;
|
||||
import static org.eclipse.che.api.machine.shared.Constants.LINK_REL_GET_MACHINE_STATUS_CHANNEL;
|
||||
import static org.eclipse.che.ide.extension.machine.client.perspective.OperationsPerspective.OPERATIONS_PERSPECTIVE_ID;
|
||||
import static org.eclipse.che.ide.ui.loaders.initialization.InitialLoadingInfo.Operations.MACHINE_BOOTING;
|
||||
import static org.eclipse.che.ide.ui.loaders.initialization.OperationInfo.Status.ERROR;
|
||||
|
|
@ -252,7 +253,7 @@ public class MachineManagerImpl implements MachineManager, WorkspaceStoppedHandl
|
|||
eventBus.fireEvent(new MachineStartingEvent(machineDto));
|
||||
|
||||
subscribeToChannel(machineDto.getConfig()
|
||||
.getLink(Constants.LINK_REL_GET_MACHINE_LOGS_CHANNEL)
|
||||
.getLink(LINK_REL_GET_MACHINE_LOGS_CHANNEL)
|
||||
.getParameter("channel")
|
||||
.getDefaultValue(),
|
||||
outputHandler);
|
||||
|
|
@ -286,6 +287,17 @@ public class MachineManagerImpl implements MachineManager, WorkspaceStoppedHandl
|
|||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDevMachineStatusTracked(MachineDto machine) {
|
||||
final LinkParameter statusChannelLinkParameter = machine.getConfig().getLink(LINK_REL_GET_MACHINE_STATUS_CHANNEL).getParameter("channel");
|
||||
if (statusChannelLinkParameter == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
String machineStatusChannel = statusChannelLinkParameter.getDefaultValue();
|
||||
return machineStatusChannel != null && messageBus.isHandlerSubscribed(statusHandler, machineStatusChannel);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Promise<Void> destroyMachine(final MachineDto machineState) {
|
||||
return machineServiceClient.destroyMachine(machineState.getId()).then(new Operation<Void>() {
|
||||
|
|
@ -306,15 +318,13 @@ public class MachineManagerImpl implements MachineManager, WorkspaceStoppedHandl
|
|||
perspectiveManager.setPerspectiveId(OPERATIONS_PERSPECTIVE_ID);
|
||||
initialLoadingInfo.setOperationStatus(MACHINE_BOOTING.getValue(), IN_PROGRESS);
|
||||
|
||||
if (machineConfig.getLink(Constants.LINK_REL_GET_MACHINE_LOGS_CHANNEL) != null &&
|
||||
machineConfig.getLink(Constants.LINK_REL_GET_MACHINE_STATUS_CHANNEL) != null) {
|
||||
final LinkParameter logsChannelLinkParameter = machineConfig.getLink(Constants.LINK_REL_GET_MACHINE_LOGS_CHANNEL)
|
||||
.getParameter("channel");
|
||||
if (machineConfig.getLink(LINK_REL_GET_MACHINE_LOGS_CHANNEL) != null &&
|
||||
machineConfig.getLink(LINK_REL_GET_MACHINE_STATUS_CHANNEL) != null) {
|
||||
final LinkParameter logsChannelLinkParameter = machineConfig.getLink(LINK_REL_GET_MACHINE_LOGS_CHANNEL).getParameter("channel");
|
||||
if (logsChannelLinkParameter != null) {
|
||||
outputChannel = logsChannelLinkParameter.getDefaultValue();
|
||||
}
|
||||
final LinkParameter statusChannelLinkParameter = machineConfig.getLink(Constants.LINK_REL_GET_MACHINE_STATUS_CHANNEL)
|
||||
.getParameter("channel");
|
||||
final LinkParameter statusChannelLinkParameter = machineConfig.getLink(LINK_REL_GET_MACHINE_STATUS_CHANNEL).getParameter("channel");
|
||||
if (statusChannelLinkParameter != null) {
|
||||
statusChannel = statusChannelLinkParameter.getDefaultValue();
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue