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-26175: cannot create server adapter for eap71-basic-s2i template #1785

Merged
merged 14 commits into from
Aug 30, 2018

Conversation

bdshadow
Copy link
Contributor

Signed-off-by: Dmitrii Bocharov dbocharo@redhat.com

A very easy and little fix, but needs to be tested a lot, as can have some unpredictable repercussions.

@@ -36,7 +36,7 @@ protected String getOutputNameFromSettings(IServerAttributes server, IModule mod
String ret = super.getOutputNameFromSettings(server, module);
if (ret == null && module.equals(findProjectModule(server))) {
String suffix = ServerModelUtilities.getDefaultSuffixForModule(module);
ret = "ROOT" + suffix;
ret = module.getName() + suffix;
Copy link
Member

Choose a reason for hiding this comment

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

That would probably fix for EAP 7.1 but for 7.0 as the OpenShift profile is probably not set you will not get the proper module name. Can you test with EAP 7.0 ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

@bdshadow Yes, since the reason for the module name not being handled correctly lies in JBIDE-22138 aka upstream. As long as upstream isn't fixed the decision whether we want to apply this fix boils down to whether we want eap-70 or eap-71 templates to fail. I'd opt for sticking to the status quo aka not applying this fix.
@jeffmaury @bdshadow thoughts?

@jeffmaury
Copy link
Member

As J2EEDeployableFactory is a singleton can't we call the clearCache from our stuff before we generate the module name ?

@adietish
Copy link
Member

adietish commented Aug 2, 2018

@jeffmaury I get the idea and yes, I agree: even though very dirty we could try to work around the bug in JBIDE-22138 and manually clear the module factory cache(s).

@jkopriva
Copy link
Member

jkopriva commented Aug 6, 2018

I am also against applying this patch, we need to have more complex solution to have both(eap70 and eap71) templates working.
As @jeffmaury mentioned, with this patch eap71 is working, but eap70 template does not work.

@bdshadow
Copy link
Contributor Author

bdshadow commented Aug 6, 2018

@adietish @jeffmaury @jkopriva "openshift" profile is now activated when an openshift server adapter is created. Anyway it doesn't solve our problems. Please, take a look and test it. WDYT?

@bdshadow
Copy link
Contributor Author

bdshadow commented Aug 7, 2018

@adietish @jkopriva i've tested it several times from scratch with a new connection and eclipse wotkspace without kitchensink project yet. It works for me.
I see a test is failing + i'll re-test the reflection stuff with java 9, but could you please verify that it works for you?

return OpenShiftServerUtils.findProjectModule(getEclipseProject(server));
}

private IProject getEclipseProject(IServerAttributes server) {
Copy link
Member

Choose a reason for hiding this comment

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

any particular reason for extracting the call to the util method to it's own private method?

return model.saveServer(monitor);
}

@SuppressWarnings("restriction")
private void setOpenshiftMavenProfileActive(IProject newDeployProject) throws CoreException {
Copy link
Member

Choose a reason for hiding this comment

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

maybe we could make this method even more useful by refactoring it to something like activateMavenProfile(String profilename, IProject project)?


@SuppressWarnings("restriction")
private void setOpenshiftMavenProfileActive(IProject newDeployProject) throws CoreException {
IFile pom = newDeployProject.getFile(IMavenConstants.POM_FILE_NAME);
Copy link
Member

Choose a reason for hiding this comment

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

the file may only be retrieved if the project has the maven nature, so the call could be easily moved to l1112 making it more logical, I think.

if (profiles.stream().anyMatch(p -> OPENSHIFT_MAVEN_PROFILE.equals(p.getId())) && !activeProfiles.contains(OPENSHIFT_MAVEN_PROFILE)) {
activeProfiles.add(OPENSHIFT_MAVEN_PROFILE);
profileManager.updateActiveProfiles(facade, activeProfiles, false, true, new NullProgressMonitor());
}
Copy link
Member

Choose a reason for hiding this comment

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

l1111-1122 could be refactored to a set of 3 methods which then would be reusable - if then moved to a common bundle :

  • ProfileData getActiveProfiles(IProject project)
  • boolean isActiveProfile(String profileId, IProject project) - optional, could be included in setActiveProfile
  • void setActiveProfile(String profileId)

Looks like a benefit if done so, agree?

@nickboldt
Copy link
Member

testPR

@adietish
Copy link
Member

adietish commented Aug 7, 2018

@bdshadow You can rebase this PR in order to fix the jenkins errors. I bumped openshift (in #1788) in order to fix the baseline check errors that caused those.

@jkopriva
Copy link
Member

jkopriva commented Aug 8, 2018

@bdshadow I have retested it with last commit and I was able to create server adapter for eap70 and eap71 template/

@bdshadow
Copy link
Contributor Author

bdshadow commented Aug 8, 2018

@jkopriva thank you
@adietish i also tested it against https://github.com/redhat-helloworld-msa/helloworld-msa/blob/master/hello.adoc (second cmd approach) and it works fine.

Now i'm going to refactor my code according to the remarks, rebase it and test against java 9.

@SuppressWarnings("restriction")
private void setOpenshiftMavenProfileActive(IProject newDeployProject) throws CoreException {
IFile pom = newDeployProject.getFile(IMavenConstants.POM_FILE_NAME);
if (newDeployProject.hasNature(IMavenConstants.NATURE_ID) && pom != null) {
Copy link
Member

Choose a reason for hiding this comment

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

checking IFile "pom" against being null isn't enough I believe. IContainer#getFile always returns an instance, regardless whether it exists or not. I think that we should also check pom.isAccessible()

List<ProfileData> profiles = profileManager.getProfileDatas(facade, new NullProgressMonitor());
List<String> activeProfiles = profiles.stream()
.filter(p -> ProfileState.Active.equals(p.getActivationState()))
.map(p -> p.getId())
Copy link
Member

Choose a reason for hiding this comment

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

this lambda can be replaced by a method reference for improved readability: ProfileData::getId

IMavenProjectFacade facade = MavenPlugin.getMavenProjectRegistry().create(pom, true, new NullProgressMonitor());
List<ProfileData> profiles = profileManager.getProfileDatas(facade, new NullProgressMonitor());
List<String> activeProfiles = profiles.stream()
.filter(p -> ProfileState.Active.equals(p.getActivationState()))
Copy link
Member

@adietish adietish Aug 8, 2018

Choose a reason for hiding this comment

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

writing down what we discussed/found out:
with a ~/.m2/settings.xml file, that also has profiles, filtering only on activation states this will have all those activated:
image

One needs to also filter autoactive profiles:

.filter(p -> ProfileState.Active.equals(p.getActivationState())
                        && !p.isAutoActive())

This will produce the correct results:
image
image

@adietish
Copy link
Member

adietish commented Aug 8, 2018

Another thing that we should do:

  • deactive the openshift profile if one stops (or deletes the server adapter)
  • activate the openshift profile if one (re-)starts the adapter

I thus think that activating the profile should be done where the adapter gets started, not upon creation like it is now

@adietish adietish force-pushed the jbide-26175 branch 2 times, most recently from 5e4401b to 9be188d Compare August 8, 2018 15:53
@adietish
Copy link
Member

adietish commented Aug 8, 2018

extracted the maven profile to it's own class MavenProfile (which can be activate and eventually deactivated) in org.jboss.tools.openshift.core.
Further work required to have it activated upon adapter start and deactivated upon adapter stop.

@adietish adietish force-pushed the jbide-26175 branch 4 times, most recently from bae57fa to 44a104e Compare August 8, 2018 21:33
@adietish
Copy link
Member

adietish commented Aug 9, 2018

@bdshadow rebased and added tests for MaveProfile

Signed-off-by: Dmitrii Bocharov <dbocharo@redhat.com>
Signed-off-by: Dmitrii Bocharov <dbocharo@redhat.com>
@jbosstools jbosstools deleted a comment from adietish Aug 10, 2018
Signed-off-by: Andre Dietisheim <adietish@redhat.com>
@adietish
Copy link
Member

testPR

Signed-off-by: Andre Dietisheim <adietish@redhat.com>
Signed-off-by: Dmitrii Bocharov <dbocharo@redhat.com>
@bdshadow
Copy link
Contributor Author

Tested with java 9. Works fine

Signed-off-by: Andre Dietisheim <adietish@redhat.com>
@adietish
Copy link
Member

adietish commented Aug 13, 2018

@bdshadow When trying the eap70 basic template, I have the project switched to the correct openshift profile but still the kitchensink.war artifact deployed. Weird enough, I see the correct clearCache(IProject) method being called by our workaround and accordingly the properties in the module holding the correct ROOT property.
When then looking at the name that's being chosen, I saw that we're using the module name (and not the deploy name as I would think we should): https://github.com/jbosstools/jbosstools-openshift/pull/1785/files#diff-a349d83b5835c45fbf04dc863de9429cR39
Prior versions of the code clearly used the deploy name property of the module. Somehow they went missing (maybe when I rebased?).
I therefore put your code back in place: 1ffdac4

Signed-off-by: Andre Dietisheim <adietish@redhat.com>
@bdshadow
Copy link
Contributor Author

bdshadow commented Aug 14, 2018

@adietish actually i removed the usage of property name. I debugged it for eap70 and eap71 and it was returning the same for both: module.getName() and property. Moreover, if null is returned, you can find in the parent class that this logic with the property retrieval is run

I don't know why it didn't work for you with eap70. I've tested it lots of times already, and once i also had such a problem, and i wrote to you about it. Then everything was fine. I have no idea why this happens sometimes

@adietish
Copy link
Member

adietish commented Aug 14, 2018

we agreed that deploying using the deploy name, rather the module name is the right way to do it.
But then we face the next issue:
When switching the deploy name, the name of the war changes. A new (exploded) war is created in the temporary server-adapter directory in Eclipse, but the old (exploded) war is not removed. This causes both wars to be deployed

Steps:

  1. have app, workspace project and server adapter in place (create the app using the eap70-basic-s2i template)
  2. make sure that the server-adapter temporary directory in Eclipse only has 1 exploded war (either ROOT.war or jboss-kitchensink.war - delete the other one) - temporary server-adapter directory in Eclipse is at <workspace>/.metadata/.plugins/org.jboss.ide.eclipse.as.core/<adapter-name>/deploy
  3. switch the maven profile of the workspace project (if it has the openshift profile, uncheck it. If it has it, check it)

Result:

a new deployed war directory is created in the temporary server-adapter directory. The existing one stays in place, it is not removed. Therefore rsync will copy both (exploded) wars to OpenShift

@robstryker thoughts?

@adietish
Copy link
Member

adietish commented Aug 14, 2018

To solve the above we have to be able to identify that a new war is to be created, the old one should be removed. I currently don't see how we can achieve this.
@robstryker can please provide some pointers? We have the "PROP_DEPLOY_NAME" property changing in a module which causes a new war to be created in the local "deploy" directory. We now need to remove the old one and remove the .deploy marker so that it gets undeployed in the wildfly in the pod.

We could simply clean the local "deploy" directory (local sever-adapter storage) before it gets rsynced up to the OpenShift pod.
The problem with that is that this wont remove the existing deployment in the (wildfly on the) pod. Resulting is an additional deployment with the new war name that conflicts with the existing one (that was not removed).
To remove that one, we'd have to kill the .deployed marker (see https://docs.jboss.org/author/display/WFLY10/Application+deployment#Applicationdeployment-MarkerFiles) which we currently don't have locally. For this to work there are a few bits missing:

  • before publishing the module to the pod, we'd have to rsync the pod down to the local "deploy" directory (in order to get the .deployed marker)
    ex. via the following:
public class OpenShiftEapPublishController extends OpenShiftPublishController implements ISubsystemController {

	@Override
	public int publishModule(int kind, int deltaKind, IModule[] module, IProgressMonitor monitor) throws CoreException {
+		rsyncDown(monitor);
		return super.publishModule(IServer.PUBLISH_CLEAN, deltaKind, module, monitor);
	}

+	private MultiStatus rsyncDown(IProgressMonitor monitor) throws CoreException {
+		final RSync rsync = OpenShiftServerUtils.createRSync(getServer(), monitor);
+		final File localDeploymentDirectory = new File(getDeploymentOptions().getDeploymentsRootFolder(true));
+		return rsync.syncPodsToDirectory(localDeploymentDirectory, ServerConsoleModel.getDefault().getConsoleWriter());
	}
  • then we'd have to remove the .deployed marker for the oudated war
  • and finally we'd have to use oc rsync --delete to make sure whatever file is deleted locally gets deleted in the pod.

@bdshadow
Copy link
Contributor Author

bdshadow commented Aug 15, 2018

by now it's better to wait for @robstryker as we can be missing smth and solution can be easier (or in the contrary we don't see smth complex). I discussed it with @adietish yesterday. It seems to me that he agreed, though he won't be available for the following 2 weeks too

Signed-off-by: Andre Dietisheim <adietish@redhat.com>
* Cache is not cleaned properly and we get an incorrect name of the module for deployment
* https://issues.jboss.org/browse/JBIDE-22138#comment-13617731
*/
private void clearJSTcache(IProject project) throws Exception {

Choose a reason for hiding this comment

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

MAJOR Define and throw a dedicated exception instead of using a generic one. rule

@adietish
Copy link
Member

adietish commented Aug 29, 2018

@bdshadow I added an additional commit which makes sure that modules get notified of the cleared module cache. Things now work for me:

ps. manually switching the maven profile once the war has already been published will NOT remove the previous jar (see #1785 (comment)). But this won't harm the intended fix for https://issues.jboss.org/browse/JBIDE-26175 where the war stays constant. I'll file this to a new issue

Signed-off-by: Andre Dietisheim <adietish@redhat.com>
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;

import junit.framework.TestCase;

@RunWith(MockitoJUnitRunner.class)
public class OpenShiftModuleDeploymentPrefsUtilTest extends TestCase {

Choose a reason for hiding this comment

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

BLOCKER Add some tests to this class. rule

@rhdevelopers-ci
Copy link

SonarQube analysis reported 6 issues

  • BLOCKER 1 blocker
  • MAJOR 5 major

Watch the comments in this conversation to review them.

@adietish adietish requested review from jeffmaury and removed request for robstryker August 30, 2018 08:35
Copy link
Member

@jeffmaury jeffmaury left a comment

Choose a reason for hiding this comment

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

+1 Tested on Win10 with both EAP7.0 and EAP7.1 quickstarts

@adietish adietish removed the request for review from jkopriva August 30, 2018 16:15
@adietish adietish merged commit 0ab3fb7 into jbosstools:master Aug 30, 2018
@adietish adietish deleted the jbide-26175 branch August 30, 2018 17:19
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.

6 participants