Skip to content

Commit

Permalink
[JBIDE-24148] load deployment config only before updating it
Browse files Browse the repository at this point in the history
changed to load deployment config as last step just before updating it
since we can run into optimistic locking problems otherwise
  • Loading branch information
adietish committed Jul 3, 2017
1 parent fd5ffdc commit 606e098
Show file tree
Hide file tree
Showing 5 changed files with 262 additions and 301 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.Set;

import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
Expand Down Expand Up @@ -86,19 +87,19 @@ public void launch(ILaunchConfiguration configuration, String mode, ILaunch laun
String currentMode = beh.getServer().getMode();
beh.setServerStarting();
launchServerProcess(beh, configuration, launch, monitor);
if (waitForDeploymentConfigReady(beh.getServer(), monitor)) {
try {
try {
if (waitForDeploymentConfigReady(beh.getServer(), monitor)) {
DebugContext context = createDebugContext(beh, monitor);
toggleDebugging(mode, beh, context, monitor);
OpenShiftDebugMode.sendChanges(context, monitor);
} catch (Exception e) {
mode = currentMode;
throw new CoreException(StatusFactory.errorStatus(OpenShiftCoreActivator.PLUGIN_ID,
NLS.bind("Could not launch server {0}", beh.getServer().getName()), e));
} finally {
setServerState(beh, mode);
}
};
} catch (Exception e) {
mode = currentMode;
throw new CoreException(StatusFactory.errorStatus(OpenShiftCoreActivator.PLUGIN_ID,
NLS.bind("Could not launch server {0}", beh.getServer().getName()), e));
} finally {
setServerState(beh, mode);
}
}

protected void launchServerProcess(OpenShiftServerBehaviour beh, ILaunchConfiguration configuration, ILaunch launch,
Expand Down Expand Up @@ -203,25 +204,54 @@ private boolean sleep(int sleep) {
}
}

protected boolean toggleDebugging(String mode, OpenShiftServerBehaviour beh, DebugContext context, IProgressMonitor monitor) throws CoreException {
protected void toggleDebugging(String mode, OpenShiftServerBehaviour beh, DebugContext context, IProgressMonitor monitor) throws CoreException {
boolean enableDebugging = isDebugMode(mode);
boolean changed = false;
if (enableDebugging) {
changed = startDebugging(beh, context, monitor);
startDebugging(beh, context, monitor);
} else { //run, profile
changed = stopDebugging(context, monitor);
stopDebugging(context, monitor);
}
return changed;
}

protected DebugContext createDebugContext(OpenShiftServerBehaviour beh, IProgressMonitor monitor) throws CoreException {
monitor.subTask("Initialising debug context...");
DockerImageLabels imageLabels = getDockerImageLabels(beh, monitor);
String devmodeKey = getDevmodeKey(beh.getServer(), imageLabels);
String debugPortKey = getDebugPortKey(beh.getServer(), imageLabels);
String debugPort = getDebugPort(beh.getServer(), imageLabels);
DebugContext debugContext = OpenShiftDebugMode.createContext(beh, devmodeKey, debugPortKey, debugPort);
return debugContext;
}

private DockerImageLabels getDockerImageLabels(OpenShiftServerBehaviour beh, IProgressMonitor monitor) throws CoreException {
IResource resource = OpenShiftServerUtils.getResource(beh.getServer());
DockerImageLabels metadata = DockerImageLabels.getInstance(resource, beh);
waitForDockerImageLabelsReady(metadata, monitor);
IDeploymentConfig dc = OpenShiftServerUtils.getDeploymentConfig(resource, OpenShiftServerUtils.getConnection(beh.getServer()));
DebugContext debugContext = OpenShiftDebugMode.createContext(dc, beh, metadata);
return debugContext;
return metadata;
}

private static String getDevmodeKey(IServer server, DockerImageLabels metadata) throws CoreException {
String devmodeKey = OpenShiftServerUtils.getDevmodeKey(server);
if (StringUtils.isBlank(devmodeKey)) {
devmodeKey = metadata.getDevmodeKey();
}
return devmodeKey;
}

private static String getDebugPortKey(IServer server, DockerImageLabels metadata) throws CoreException {
String debugPortKey = OpenShiftServerUtils.getDebugPortKey(server);
if (StringUtils.isBlank(debugPortKey)) {
debugPortKey = metadata.getDevmodePortKey();
}
return debugPortKey;
}

private static String getDebugPort(IServer server, DockerImageLabels metadata) throws CoreException {
String debugPort = OpenShiftServerUtils.getDebugPort(server);
if (StringUtils.isBlank(debugPort)) {
debugPort = metadata.getDevmodePortValue();
}
return debugPort;
}

protected void setServerState(OpenShiftServerBehaviour beh, String mode) {
Expand Down Expand Up @@ -283,7 +313,7 @@ protected IStatus run(IProgressMonitor monitor) {
}.schedule(PUBLISH_DELAY);
}

protected boolean startDebugging(OpenShiftServerBehaviour behaviour, DebugContext context,
protected void startDebugging(OpenShiftServerBehaviour behaviour, DebugContext context,
IProgressMonitor monitor) throws CoreException {
IDebugListener listener = new IDebugListener() {

Expand All @@ -305,18 +335,18 @@ public void onPodRestart(DebugContext debuggingContext, IProgressMonitor monitor
}
};
context.setDebugListener(listener);
return OpenShiftDebugMode.enableDebugging(context, monitor);
OpenShiftDebugMode.enableDebugging(context, monitor);
}

private boolean stopDebugging(DebugContext debugContext, IProgressMonitor monitor)
private void stopDebugging(DebugContext debugContext, IProgressMonitor monitor)
throws CoreException {
IDebugListener listener = new IDebugListener() {

@Override
public void onDebugChange(DebugContext debuggingContext, IProgressMonitor monitor)
public void onDebugChange(DebugContext context, IProgressMonitor monitor)
throws CoreException {
DebugLaunchConfigs.get().terminateRemoteDebugger(getServer());
unMapPortForwarding(debuggingContext.getPod());
unMapPortForwarding(OpenShiftDebugMode.getFirstPod(context));
}

@Override
Expand All @@ -325,7 +355,7 @@ public void onPodRestart(DebugContext debuggingContext, IProgressMonitor monitor
}
};
debugContext.setDebugListener(listener);
return OpenShiftDebugMode.disableDebugging(debugContext, monitor);
OpenShiftDebugMode.disableDebugging(debugContext, monitor);
}

@Override
Expand Down Expand Up @@ -365,7 +395,7 @@ private void unMapPortForwarding(IPod pod) throws CoreException {
protected int mapPortForwarding(final DebugContext context, final IProgressMonitor monitor) throws CoreException {
monitor.subTask("Starting port forwarding...");

IPod pod = context.getPod();
IPod pod = OpenShiftDebugMode.getFirstPod(context);
if (pod == null) {
throw new CoreException(StatusFactory.errorStatus(OpenShiftCoreActivator.PLUGIN_ID,
NLS.bind("Could not find running pod to forward to in server adapter \"{0}\"", getServer().getName())));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,17 @@ public class OpenShiftResourceUniqueId {
private static final char UNIQUE_ID_PROJECT_NAME_DELIMITER = '@';

public static String get(IResource resource) {
if (resource == null || StringUtils.isEmpty(resource.getName()) || resource.getProject() == null
|| StringUtils.isEmpty(resource.getProject().getName())) {
if (resource == null
|| StringUtils.isEmpty(resource.getName())
|| StringUtils.isEmpty(resource.getNamespace())) {
return null;
}

if (ResourceKind.SERVICE.equals(resource.getKind())) {
return new StringBuilder().append(resource.getProject().getName()).append(UNIQUE_ID_PROJECT_NAME_DELIMITER)
return new StringBuilder().append(resource.getNamespace()).append(UNIQUE_ID_PROJECT_NAME_DELIMITER)
.append(resource.getName()).toString();
} else {
return new StringBuilder().append(resource.getProject().getName()).append(UNIQUE_ID_PROJECT_NAME_DELIMITER)
return new StringBuilder().append(resource.getNamespace()).append(UNIQUE_ID_PROJECT_NAME_DELIMITER)
.append(resource.getKind()).append(UNIQUE_ID_PROJECT_NAME_DELIMITER)
.append(resource.getName()).toString();
}
Expand Down

0 comments on commit 606e098

Please sign in to comment.