Skip to content

Commit

Permalink
[JBIDE-24148] fix nodejs server adapter
Browse files Browse the repository at this point in the history
  • Loading branch information
adietish committed Jun 26, 2017
1 parent 019bd6d commit a79af5c
Show file tree
Hide file tree
Showing 30 changed files with 770 additions and 590 deletions.
3 changes: 2 additions & 1 deletion plugins/org.jboss.tools.openshift.core/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ Require-Bundle: org.jboss.tools.openshift.client;bundle-version="[3.0.0,4.0.0)",
com.fasterxml.jackson.core.jackson-core;bundle-version="2.5.0",
org.jboss.tools.jmx.jolokia;bundle-version="1.8.2",
org.jboss.ide.eclipse.as.jmx.integration,
org.eclipse.linuxtools.docker.core
org.eclipse.linuxtools.docker.core,
org.apache.commons.collections
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Bundle-ActivationPolicy: lazy
Export-Package: org.jboss.tools.openshift.core,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,8 @@
*/
public interface OpenShiftResourceSelectors {

static final String DEPLOYMENT_CONFIG = "deploymentConfig";
/** as in eap templates **/
static final String DEPLOYMENT_CONFIG_CAMELCASE = "deploymentConfig";
/** as in nodejs templates **/
static final String DEPLOYMENT_CONFIG_LOWERCASE = "deploymentconfig";
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2016 Red Hat Inc..
* Copyright (c) 2016-2017 Red Hat Inc..
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -428,14 +428,18 @@ public static IControllableServerBehavior getBehaviour(IServer server) {
return server.getAdapter(IControllableServerBehavior.class);
}

public static OpenShiftServerBehaviour getOpenShiftServerBehaviour(ILaunchConfiguration configuration) throws CoreException {
IControllableServerBehavior serverBehavior = getBehaviour(ServerUtil.getServer(configuration));
public static OpenShiftServerBehaviour getOpenShiftServerBehaviour(IServer server) throws CoreException {
IControllableServerBehavior serverBehavior = getBehaviour(server);
if (!(serverBehavior instanceof OpenShiftServerBehaviour)) {
throw toCoreException("Unable to find a OpenShiftServerBehaviour instance");
}
return (OpenShiftServerBehaviour) serverBehavior;
}

public static OpenShiftServerBehaviour getOpenShiftServerBehaviour(ILaunchConfiguration configuration) throws CoreException {
return getOpenShiftServerBehaviour(ServerUtil.getServer(configuration));
}

/**
* Creates an {@link RSync}
* @param server the {@link IServer} on which the {@code rsync} operation will be performed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@
import org.jboss.tools.openshift.core.server.OpenShiftServerUtils;
import org.jboss.tools.openshift.internal.core.OpenShiftCoreActivator;
import org.jboss.tools.openshift.internal.core.portforwarding.PortForwardingUtils;
import org.jboss.tools.openshift.internal.core.server.debug.DebugLaunchConfigs;
import org.jboss.tools.openshift.internal.core.server.debug.DebuggingContext;
import org.jboss.tools.openshift.internal.core.server.debug.IDebugListener;
import org.jboss.tools.openshift.internal.core.server.debug.OpenShiftDebugUtils;
import org.jboss.tools.openshift.internal.core.server.debug.OpenShiftDebugMode;
import org.jboss.tools.openshift.internal.core.util.ResourceUtils;

import com.openshift.restclient.OpenShiftException;
import com.openshift.restclient.ResourceKind;
import com.openshift.restclient.capability.IBinaryCapability.OpenShiftBinaryOption;
import com.openshift.restclient.capability.resources.IPortForwardable;
Expand All @@ -63,12 +63,15 @@
import com.openshift.restclient.model.IReplicationController;
import com.openshift.restclient.model.IResource;

public class OpenShiftLaunchController
extends AbstractSubsystemController
implements ISubsystemController, ILaunchServerController {
/**
* @author Rob Stryker
* @author Fred Bricon
* @author Jeff Maury
* @author Andre Dietisheim
*/
public class OpenShiftLaunchController extends AbstractSubsystemController implements ISubsystemController, ILaunchServerController {

private static final String LAUNCH_DEBUG_PORT_PROP = "LOCAL_DEBUG_PORT";

private static final int RETRY_DELAY = 1000;
private static final int PUBLISH_DELAY = 3000;
private static final String DEBUG_MODE = "debug"; //$NON-NLS-1$
Expand All @@ -84,8 +87,10 @@ public void launch(ILaunchConfiguration configuration, String mode, ILaunch laun
try {
toggleDebugging(mode, monitor, beh);
} catch (CoreException e) {
beh.setServerStopped();
mode = server.getMode();
throw e;
} finally {
setServerState(beh, mode);
}
};
}
Expand Down Expand Up @@ -161,29 +166,22 @@ private void sleep(long t) {

protected boolean toggleDebugging(String mode, IProgressMonitor monitor, OpenShiftServerBehaviour beh) throws CoreException {
IServer server = beh.getServer();
String currentMode = server.getMode();
IReplicationController rc = OpenShiftServerUtils.getReplicationController(server);
DebuggingContext debugContext = OpenShiftDebugUtils.get().getDebuggingContext(rc, beh);
boolean enableDebugging = DEBUG_MODE.equals(mode);
try {
if (enableDebugging) {
startDebugging(rc, beh, debugContext, monitor);
} else {//run, profile
stopDebugging(rc, debugContext, monitor);
}
} catch (CoreException e) {
mode = currentMode;
throw e;
} finally {
setServerState(beh, currentMode, mode);
DebuggingContext debugContext = OpenShiftDebugMode.createContext(rc, beh);
boolean enableDebugging = isDebugMode(mode);
if (enableDebugging) {
startDebugging(beh, debugContext, monitor);
} else { //run, profile
stopDebugging(debugContext, monitor);
}
return enableDebugging;
}
private void setServerState(OpenShiftServerBehaviour beh, String oldMode, String mode) {

protected void setServerState(OpenShiftServerBehaviour beh, String mode) {
int state = pollState();
String currentMode = beh.getServer().getMode();

if (!Objects.equals(oldMode, mode)) {
if (!Objects.equals(currentMode, mode)) {
setModulesPublishing();
if (state == IServer.STATE_STARTED
&& beh.isRestarting()) {
Expand All @@ -201,6 +199,26 @@ private void setServerState(OpenShiftServerBehaviour beh, String oldMode, String
}
}

protected int pollState() {
IResource resource = null;
Exception e = null;
resource = OpenShiftServerUtils.getResource(getServer());
if (resource == null) {
OpenShiftCoreActivator.pluginLog().logError(
"The OpenShift resource for server " + getServer().getName() + " could not be reached.", e);
return IServer.STATE_STOPPED;
}
return IServer.STATE_STARTED;
}

protected boolean isDebugMode() {
return isDebugMode(getServer().getMode());
}

protected boolean isDebugMode(String mode) {
return DEBUG_MODE.equals(mode);
}

private void setModulesPublishing() {
IModule[] modules = getServer().getModules();
for (int i = 0; i < modules.length; i++) {
Expand All @@ -218,12 +236,8 @@ protected IStatus run(IProgressMonitor monitor) {
}.schedule(PUBLISH_DELAY);
}

protected void startDebugging(IReplicationController rc, OpenShiftServerBehaviour behaviour, DebuggingContext context,
protected void startDebugging(OpenShiftServerBehaviour behaviour, DebuggingContext context,
IProgressMonitor monitor) throws CoreException {
// int remotePort = debugContext.getDebugPort();
// if (remotePort == DebuggingContext.NO_DEBUG_PORT) {
// updateDebugContext(rc, behaviour, debugContext);
// }
IDebugListener listener = new IDebugListener() {

@Override
Expand All @@ -247,42 +261,17 @@ public void onPodRestart(DebuggingContext debuggingContext, IProgressMonitor mon
}
};
context.setDebugListener(listener);
OpenShiftDebugUtils.get().enableDebugging(rc, context, monitor);
OpenShiftDebugMode.enableDebugging(context, monitor);
}

// private void updateDebugContext(IReplicationController rc, OpenShiftServerBehaviour behaviour,
// DebuggingContext debugContext) throws CoreException {
// IServer server = behaviour.getServer();
// DockerImageLabels metadata = DockerImageLabels.getInstance(rc, behaviour);
//
// String devmodeKey = OpenShiftServerUtils.getDevmodeKey(server);
// if (StringUtils.isEmpty(devmodeKey)) {
// devmodeKey = metadata.getDevmodeKey();
// }
// debugContext.setDevmodeKey(devmodeKey);
//
// String debugPortKey = OpenShiftServerUtils.getDebugPortKey(server);
// if (StringUtils.isEmpty(debugPortKey)) {
// debugPortKey = metadata.getDevmodePortKey();
// }
// debugContext.setDebugPortKey(debugPortKey);
//
// String debugPortValue = OpenShiftServerUtils.getDebugPort(server);
// if (StringUtils.isEmpty(debugPortValue)) {
// debugPortValue = metadata.getDevmodePortValue();
// }
// debugContext.setDebugPort(debugPortValue);
// }


private void stopDebugging(IReplicationController rc, DebuggingContext debugContext, IProgressMonitor monitor)
private void stopDebugging(DebuggingContext debugContext, IProgressMonitor monitor)
throws CoreException {
IDebugListener listener = new IDebugListener() {

@Override
public void onDebugChange(DebuggingContext debuggingContext, IProgressMonitor monitor)
throws CoreException {
OpenShiftDebugUtils.get().terminateRemoteDebugger(getServer());
DebugLaunchConfigs.get().terminateRemoteDebugger(getServer());
unMapPortForwarding(debuggingContext.getPod());
}

Expand All @@ -292,24 +281,9 @@ public void onPodRestart(DebuggingContext debuggingContext, IProgressMonitor mon
}
};
debugContext.setDebugListener(listener);
OpenShiftDebugUtils.get().disableDebugging(rc, debugContext, monitor);
OpenShiftDebugMode.disableDebugging(debugContext, monitor);
}

protected int pollState() {
IResource resource = null;
Exception e = null;
try {
resource = OpenShiftServerUtils.getResource(getServer());
} catch(OpenShiftException ose ) {
e = ose;
}
if (resource == null) {
OpenShiftCoreActivator.pluginLog().logError("The OpenShift resource for server " + getServer().getName() + " could not be reached.", e);
return IServer.STATE_STOPPED;
}
return IServer.STATE_STARTED;
}

@Override
public IStatus canStart(String launchMode) {
return Status.OK_STATUS;
Expand Down Expand Up @@ -383,11 +357,11 @@ protected int mapPortForwarding(final DebuggingContext debuggingContext, final I
private ILaunch attachRemoteDebugger(IServer server, int localDebugPort, IProgressMonitor monitor) throws CoreException {
monitor.subTask("Attaching remote debugger");
ILaunch ret = null;
OpenShiftDebugUtils debugUtils = OpenShiftDebugUtils.get();
ILaunchConfiguration debuggerLaunchConfig = debugUtils.getRemoteDebuggerLaunchConfiguration(server);
ILaunchConfigurationWorkingCopy workingCopy = getLaunchConfigWorkingCopy(server, debugUtils, debuggerLaunchConfig);
DebugLaunchConfigs launchConfigs = DebugLaunchConfigs.get();
ILaunchConfiguration debuggerLaunchConfig = launchConfigs.getRemoteDebuggerLaunchConfiguration(server);
ILaunchConfigurationWorkingCopy workingCopy = getLaunchConfigWorkingCopy(server, launchConfigs, debuggerLaunchConfig);
IProject project = OpenShiftServerUtils.getDeployProject(server);
debugUtils.setupRemoteDebuggerLaunchConfiguration(workingCopy, project, localDebugPort);
launchConfigs.setupRemoteDebuggerLaunchConfiguration(workingCopy, project, localDebugPort);
debuggerLaunchConfig = workingCopy.doSave();

long elapsed = 0;
Expand Down Expand Up @@ -422,13 +396,13 @@ private ILaunch attachRemoteDebugger(IServer server, int localDebugPort, IProgre
return ret;
}

private ILaunchConfigurationWorkingCopy getLaunchConfigWorkingCopy(IServer server, OpenShiftDebugUtils debugUtils,
private ILaunchConfigurationWorkingCopy getLaunchConfigWorkingCopy(IServer server, DebugLaunchConfigs launchConfigs,
ILaunchConfiguration debuggerLaunchConfig) throws CoreException {
ILaunchConfigurationWorkingCopy workingCopy;
if (debuggerLaunchConfig == null) {
workingCopy = debugUtils.createRemoteDebuggerLaunchConfiguration(server);
workingCopy = launchConfigs.createRemoteDebuggerLaunchConfiguration(server);
} else {
if (debugUtils.isRunning(debuggerLaunchConfig)) {
if (launchConfigs.isRunning(debuggerLaunchConfig)) {
return null;
}
workingCopy = debuggerLaunchConfig.getWorkingCopy();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2016 Red Hat Inc..
* Copyright (c) 2016-2017 Red Hat Inc..
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
import org.jboss.ide.eclipse.as.wtp.core.server.behavior.ISubsystemController;
import org.jboss.tools.openshift.core.server.OpenShiftServerBehaviour;
import org.jboss.tools.openshift.internal.core.OpenShiftCoreActivator;
import org.jboss.tools.openshift.internal.core.server.debug.OpenShiftDebugUtils;
import org.jboss.tools.openshift.internal.core.server.debug.DebugLaunchConfigs;
import org.jboss.tools.openshift.internal.core.server.debug.OpenShiftDebugMode;

public class OpenShiftShutdownController extends AbstractSubsystemController
implements ISubsystemController, IServerShutdownController {
Expand All @@ -43,7 +44,7 @@ public void stop(boolean force) {
OpenShiftServerBehaviour behavior = getBehavior();
behavior.setServerStopping();
try {
OpenShiftDebugUtils.get().terminateRemoteDebugger(behavior.getServer());
DebugLaunchConfigs.get().terminateRemoteDebugger(behavior.getServer());
behavior.setServerStopped();
} catch(CoreException ce) {
log(IStatus.ERROR, "Error shutting down server", ce);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import org.jboss.tools.openshift.core.connection.Connection;
import org.jboss.tools.openshift.core.connection.ConnectionPersistency;
import org.jboss.tools.openshift.core.preferences.OpenShiftCorePreferences;
import org.jboss.tools.openshift.internal.core.server.resources.OpenshiftResourceChangeListener;
import org.jboss.tools.openshift.internal.core.server.resources.ResourceChangePublisher;
import org.osgi.framework.BundleContext;

/**
Expand All @@ -37,7 +37,7 @@ public class OpenShiftCoreActivator extends BaseCorePlugin {
public static final String PLUGIN_ID = "org.jboss.tools.openshift.core"; //$NON-NLS-1$
private static OpenShiftCoreActivator instance;
private IServerLifecycleListener serverListener;
private OpenshiftResourceChangeListener resourceChangeListener;
private ResourceChangePublisher resourceChangeListener;
public OpenShiftCoreActivator() {
super();
instance = this;
Expand Down Expand Up @@ -102,7 +102,7 @@ public void connectionChanged(IConnection connection, String property, Object ol
});
ServerCore.addServerLifecycleListener(getServerListener());
// A clone of the auto-publish thread implementation
resourceChangeListener = new OpenshiftResourceChangeListener();
resourceChangeListener = new ResourceChangePublisher();
ResourcesPlugin.getWorkspace().addResourceChangeListener(resourceChangeListener, IResourceChangeEvent.POST_BUILD | IResourceChangeEvent.PRE_CLOSE | IResourceChangeEvent.PRE_DELETE);

}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2016 Red Hat, Inc.
* Copyright (c) 2016-2017 Red Hat, Inc.
* Distributed under license by Red Hat, Inc. All rights reserved.
* This program is made available under the terms of the
* Eclipse Public License v1.0 which accompanies this distribution,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2016 Red Hat.
* Copyright (c) 2016-2017 Red Hat.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
/*******************************************************************************
* Copyright (c) 2017 Red Hat, Inc.
* Distributed under license by Red Hat, Inc. All rights reserved.
* This program is made available under the terms of the
* Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Red Hat, Inc. - initial API and implementation
******************************************************************************/
package org.jboss.tools.openshift.internal.core.docker;

import java.util.regex.Matcher;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2015 Red Hat, Inc.
* Copyright (c) 2016-2017 Red Hat, Inc.
* Distributed under license by Red Hat, Inc. All rights reserved.
* This program is made available under the terms of the
* Eclipse Public License v1.0 which accompanies this distribution,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2016 Red Hat, Inc.
* Copyright (c) 2016-2017 Red Hat, Inc.
* Distributed under license by Red Hat, Inc. All rights reserved.
* This program is made available under the terms of the
* Eclipse Public License v1.0 which accompanies this distribution,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2016 Red Hat, Inc.
* Copyright (c) 2016-2017 Red Hat, Inc.
* Distributed under license by Red Hat, Inc. All rights reserved.
* This program is made available under the terms of the
* Eclipse Public License v1.0 which accompanies this distribution,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
/*******************************************************************************
* Copyright (c) 2016-2017 Red Hat, Inc.
* Distributed under license by Red Hat, Inc. All rights reserved.
* This program is made available under the terms of the
* Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Red Hat, Inc. - initial API and implementation
******************************************************************************/
package org.jboss.tools.openshift.internal.core.docker;

import org.eclipse.core.runtime.IProgressMonitor;
Expand Down

0 comments on commit a79af5c

Please sign in to comment.