Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[JBIDE-24184] get debug port and devmode switch from image #1518

Merged
merged 1 commit into from Aug 10, 2017

Conversation

adietish
Copy link
Member

@adietish adietish commented Jun 19, 2017

Pull Request Checklist

General

  • Is this a blocking issue or new feature? If yes, QE needs to +1 this PR

Code

  • Are method-/class-/variable-names meaningful?
  • Are methods concise, not too long?
  • Are catch blocks catching precise Exceptions only (no catch all)?

Testing

  • Are there unit-tests?
  • Are there integration tests (or at least a jira to tackle these)?
  • Is the non-happy path working, too?
  • Are other parts that use the same component still working fine?

Function

  • Does it work?

@adietish adietish force-pushed the JBIDE-24184 branch 12 times, most recently from 59d1780 to a79af5c Compare June 26, 2017 21:44
@adietish adietish force-pushed the JBIDE-24184 branch 4 times, most recently from 714d04f to 606e098 Compare July 3, 2017 20:23
@adietish
Copy link
Member Author

adietish commented Jul 4, 2017

@bdshadow @jeffmaury @rhopp could you please test this huge one?

the changes here are (among a general overhaul of the server adapter code):

  • allow users to provide env keys to enable/disable dev_mode, debug_port and the debug port value
  • use docker image provided values if the user chooses not to provide those
  • if devmode has to be enabled on top of debug_mode, do that in a single update

@adietish adietish force-pushed the JBIDE-24184 branch 2 times, most recently from 8d412e4 to f0ba3c6 Compare July 4, 2017 21:03
Copy link
Contributor

@bdshadow bdshadow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Andre, look at some of the remarks after a quick look. Of course i'll review and test it more later.

* @param collection
* @return
*/
public static <T> boolean isEmpty(Collection<T> collection) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't think that we really need it. Apache CollectionUtils has already this method and can be seen from all the places of usage of this isEmpty.

}
return ValidationStatus.ok();
}

protected boolean isDisabled() {
Boolean disabled = this.disabledObservable.getValue();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return this.disabledObservable.getValue(); is enough here

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i dont think so, since it could be null

DockerImageURI uri = trigger.getFrom();

return getImageStreamTag(uri, resource.getNamespace());
// String imageRef = getImageRef(dc, connection);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need such a big comment left here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@adietish i think we can remove it

boolean running = POD_STATE_RUNNING.equalsIgnoreCase(it.next().getStatus());
if (expectedRunning == !running) {
return false;
} else if (expectedRunning == running) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

smth really strange is going here. If we go to else, there is no sense to check expectedRunning == running - it'll be 100% true. And why do we return false in both cases?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lol, indeed +100. this looks like a snippet worth publishing to "coding horror".

}

@Test
public void testEnableDebug() throws CoreException {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

possibly, worth deleting these comments too

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this test is in the doing

@bdshadow
Copy link
Contributor

@adietish tested multiple times with eap application. Can't debug it ;(

  1. create eap70-basic-s2i application
  2. create server adapter (based on pod or service - doesn't matter)
  3. restart server adapter in debug mode
    4 (optional to make sure server adapter deploy changes)) Try to change smth in java code and make sure the changes are applied
  4. put breakpoint somewhere
  5. try to execute smth in application so that the line with breakpoint would be used.
  6. breakpoint was not

@adietish
Copy link
Member Author

adietish commented Jul 10, 2017

@bdshadow
I believe that I found the problem. Debugging is correctly initiated but an outdated pod is being used (when enabling debugging a new pod is launched, but the code is still referring to the terminated pod). I see this by the following:
In the Eclipse log I see the following exception (notice the pod name):

Caused by: org.eclipse.core.runtime.CoreException: Pod port specified in server adapter "eap-app (Service) at OpenShift 3 (192.168.64.2)" is no present in pod "eap-app-1-vtz7b"

while in the explorer, as child of the service, I see a different pod namely eap-app-1-qtnkb

*
* @author Andre Dietisheim
*/
public interface OpenShiftResourceSelectors {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CRITICAL Move constants to a class or enum. rule

@@ -27,24 +29,27 @@
private static final String ENV = "Env";
private static final String EXPOSED_PORT = "ExposedPorts";
private static final String VOLUMES = "Volumes";
private static final String LABELS = "Labels";

private final ModelNode node;
private final String [] CONFIG_ROOT;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MINOR Rename this field "CONFIG_ROOT" to match the regular expression '^[a-z][a-zA-Z0-9]*$'. rule

@@ -27,24 +29,27 @@
private static final String ENV = "Env";
private static final String EXPOSED_PORT = "ExposedPorts";
private static final String VOLUMES = "Volumes";
private static final String LABELS = "Labels";

private final ModelNode node;
private final String [] CONFIG_ROOT;
private final String[] PORT_KEY;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MINOR Rename this field "PORT_KEY" to match the regular expression '^[a-z][a-zA-Z0-9]*$'. rule

@@ -27,24 +29,27 @@
private static final String ENV = "Env";
private static final String EXPOSED_PORT = "ExposedPorts";
private static final String VOLUMES = "Volumes";
private static final String LABELS = "Labels";

private final ModelNode node;
private final String [] CONFIG_ROOT;
private final String[] PORT_KEY;
private final String[] VOLUMES_KEY;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MINOR Rename this field "VOLUMES_KEY" to match the regular expression '^[a-z][a-zA-Z0-9]*$'. rule

@@ -27,24 +29,27 @@
private static final String ENV = "Env";
private static final String EXPOSED_PORT = "ExposedPorts";
private static final String VOLUMES = "Volumes";
private static final String LABELS = "Labels";

private final ModelNode node;
private final String [] CONFIG_ROOT;
private final String[] PORT_KEY;
private final String[] VOLUMES_KEY;
private final String[] ENV_KEY;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MINOR Rename this field "ENV_KEY" to match the regular expression '^[a-z][a-zA-Z0-9]*$'. rule

@adietish
Copy link
Member Author

adietish commented Aug 9, 2017

@jeffmaury @bdshadow as discussed and agreed upon we should merge this asap when branch freeze is repealed

Connection connection = ConnectionsRegistryUtil.getConnectionFor(rc);
List<IPod> allPods = connection.getResources(ResourceKind.POD, rc.getNamespace());
return ResourceUtils.getPodsFor(rc, allPods).stream()
.filter(pod -> ResourceUtils.isRuntimePod(pod))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MAJOR Rename "pod" which hides the field declared at line 53. rule

@adietish adietish force-pushed the JBIDE-24184 branch 3 times, most recently from 605e45e to 896303f Compare August 10, 2017 14:03
*/
public boolean isRunning(ILaunchConfiguration launchConfiguration) {
return getLaunches()
.filter(l -> !l.isTerminated() && launchMatches(l, launchConfiguration))
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MINOR Replace this "filter().findFirst().isPresent()" chain with "anyMatch()" rule

@adietish adietish force-pushed the JBIDE-24184 branch 4 times, most recently from 7808af3 to 9b82489 Compare August 10, 2017 14:46
if (dc == null) {
throw new CoreException(StatusFactory.errorStatus(
OpenShiftCoreActivator.PLUGIN_ID, "No deployment config present that can be updated."));
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this complaint is false! the "|" is used on purpose so that both bethods are ALWAYS executed.

@adietish adietish force-pushed the JBIDE-24184 branch 2 times, most recently from 62ee9a2 to b5cc2c1 Compare August 10, 2017 14:56
public static DebugContext createContext(IControllableServerBehavior behaviour, String devmodeKey, String debugPortKey, String debugPort) {
Assert.isNotNull(behaviour);

DebugContext context = new DebugContext(behaviour,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MINOR Immediately return this expression instead of assigning it to the temporary variable "context". rule

}

public void setupRemoteDebuggerLaunchConfiguration(ILaunchConfigurationWorkingCopy workingCopy, IProject project, int debugPort)
throws CoreException {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MINOR Remove the declaration of thrown exception 'org.eclipse.core.runtime.CoreException', as it cannot be thrown from method's body. rule

IControllableServerBehavior behavior = server.getAdapter(IControllableServerBehavior.class);
return behavior;
protected void launchServerProcess(OpenShiftServerBehaviour beh, ILaunch launch,
IProgressMonitor monitor) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MAJOR Remove this unused method parameter "monitor". rule

monitor.subTask("waiting for docker image to become available...");
while (!monitor.isCanceled()) {
while (!metadata.load()
&& sleep(RECHECK_DELAY)) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MAJOR Either remove or fill this block of code. rule

ILaunch debuggerLaunch = attachRemoteDebugger(server, localPort, monitor);
if( debuggerLaunch != null ) {
if (debuggerLaunch != null) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MAJOR Remove this expression which always evaluates to "true" rule

(kind == IncrementalProjectBuilder.FULL_BUILD) ||
((kind == IncrementalProjectBuilder.AUTO_BUILD &&
ResourcesPlugin.getWorkspace().isAutoBuilding()));
kind == IncrementalProjectBuilder.INCREMENTAL_BUILD

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MINOR Immediately return this expression instead of assigning it to the temporary variable "eventOccurred". rule

return images.iterator().next();
}

private String getImageStreamTag(String imageDigest, String imageRef, String namespace, Connection connection) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MAJOR Remove this unused private "getImageStreamTag" method. rule
MAJOR Remove this unused method parameter "imageRef". rule

}

if (updateDebugmode(dc, context, monitor)
| updateDevmode(dc, context, monitor)) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BLOCKER Correct this "|" to "||". rule


private void stopDebugging(IReplicationController rc, DebuggingContext debugContext, IProgressMonitor monitor)
throws CoreException {
private void stopDebugging(DebugContext debugContext, IProgressMonitor monitor) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MAJOR Remove this unused method parameter "monitor". rule

@adietish adietish force-pushed the JBIDE-24184 branch 2 times, most recently from 33515d0 to ae953c6 Compare August 10, 2017 15:44
Signed-off-by: Andre Dietisheim <adietish@redhat.com>
debugContext.setDebugPort(8787);//TODO get default port from server settings?
}
protected void startDebugging(OpenShiftServerBehaviour behaviour, DebugContext context,
IProgressMonitor monitor) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MAJOR Remove this unused method parameter "monitor". rule

@rhdevelopers-ci
Copy link

SonarQube analysis reported 61 issues

  • BLOCKER 1 blocker
  • CRITICAL 2 critical
  • MAJOR 36 major
  • MINOR 17 minor
  • INFO 5 info

Watch the comments in this conversation to review them.

7 extra issues

Note: The following issues were found on lines that were not modified in the pull request. Because these issues can't be reported as line comments, they are summarized here:

  1. MAJOR OpenShiftLaunchController.java#L490: Remove this expression which always evaluates to "true" rule
  2. MAJOR ProgressJob.java#L18: Take the required action to fix the issue indicated by this comment. rule
  3. MAJOR ProgressJob.java#L55: Either re-interrupt this method or rethrow the "InterruptedException". rule
  4. MAJOR PushImageToRegistryJob.java#L69: Take the required action to fix the issue indicated by this comment. rule
  5. MAJOR ResourceChangePublisher.java#L181: Remove this unused "delta" private field. rule
  6. MAJOR ResourceChangePublisher.java#L184: Remove this unused "changes" private field. rule
  7. INFO DockerConfigMetaData.java#L35: Complete the task associated to this TODO comment. rule

@adietish adietish merged commit d391585 into jbosstools:master Aug 10, 2017
@adietish adietish deleted the JBIDE-24184 branch August 10, 2017 17:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants