bmuschko / gradle-cargo-plugin

Gradle plugin that provides deployment capabilities to local and remote containers via Cargo
Apache License 2.0
258 stars 61 forks source link

Port connection not reached #162

Open jeusdi opened 7 years ago

jeusdi commented 7 years ago

I'm getting this message:

14:23:42.135 [DEBUG] [sun.net.www.protocol.http.HttpURLConnection] sun.net.www.MessageHeader@26b625127 pairs: {POST /management/add-content HTTP/1.1: null}{Connection: close}{Content-Type: multipart/form-data; boundary=CargoBoundary}{User-Agent: Java/1.8.0_45}{Host: localhost:9990}{Accept: text/html, image/gif, image/jpeg, ; q=.2, /; q=.2}{Content-Length: 29831794} 14:23:42.253 [DEBUG] [sun.net.www.protocol.http.HttpURLConnection] sun.net.www.MessageHeader@1fdcbf871 pairs: {Content-type: unknown/unknown} 14:23:42.254 [DEBUG] [org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter] Finished executing task ':deployDevWildfly10' 14:23:42.254 [LIFECYCLE] [class org.gradle.internal.buildevents.TaskExecutionLogger] :deployDevWildfly10 FAILED 14:23:42.254 [INFO] [org.gradle.execution.taskgraph.AbstractTaskPlanExecutor] :deployDevWildfly10 (Thread[Daemon worker Thread 5,5,main]) completed. Took 2.664 secs. 14:23:42.254 [DEBUG] [org.gradle.internal.operations.DefaultBuildOperationWorkerRegistry] Worker root.5 completed (0 in use) 14:23:42.254 [DEBUG] [org.gradle.execution.taskgraph.AbstractTaskPlanExecutor] Task worker [Thread[Daemon worker Thread 5,5,main]] finished, busy: 2.991 secs, idle: 0.001 secs 14:23:42.255 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] 14:23:42.255 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] FAILURE: Build failed with an exception. 14:23:42.255 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] 14:23:42.255 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] What went wrong: 14:23:42.255 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] Execution failed for task ':deployDevWildfly10'. 14:23:42.255 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] > org.codehaus.cargo.util.CargoException: HTTP request failed, response code: -1, response message: null, response body: 14:23:42.255 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] 14:23:42.255 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] * Try: 14:23:42.255 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] Run with --stacktrace option to get the stack trace. 14:23:42.255 [LIFECYCLE] [org.gradle.internal.buildevents.BuildResultLogger] 14:23:42.255 [LIFECYCLE] [org.gradle.internal.buildevents.BuildResultLogger] BUILD FAILED 14:23:42.255 [LIFECYCLE] [org.gradle.internal.buildevents.BuildResultLogger] 14:23:42.255 [LIFECYCLE] [org.gradle.internal.buildevents.BuildResultLogger] Total time: 5.263 secs

Nevertheless, my task sets the port to connect to is 9992 instead of used 9990! So, the connection is refused! How could I change the port?

def remoteContainers = [
    new RemoteContainer(
        name: 'wildfly10',
        container: 'wildfly10x',
        hostname: 'localhost',
        port: 9992,
        username: '----',
        password: '----',
        purpose: 'development'
    )
]

remoteContainers.each { config ->
    task "deployDev${config.name.capitalize()}"(type: com.bmuschko.gradle.cargo.tasks.remote.CargoDeployRemote) {
        description = "Deploys WAR to remote Web Application Server: '${config.name}'."
        containerId = config.container
        hostname = config.hostname
        port = config.port
        username = config.username
        password = config.password
        context = "webapi"
        dependsOn = [createDevelopmentWar]
    }
}
bmuschko commented 7 years ago

Seems to work properly for me with your provided sample project. I see the following output when run with gradle deployDevWildfly10 -i.

Deployable artifacts = [/Users/bmuschko/dev/projects/gradle-playground/cargo/build/dist/webapi-dev-.war]
Starting action 'deploy' for remote container 'wildfly10x' on 'http://localhost:2200'

BTW: Did you intend to post your password in the code sample?

jeusdi commented 7 years ago

I've just realized that I'm getting different messages when I'm using --debug and --info.

When I perform gradle deployDevWildfly10 --info I'm getting this message:

Deployable artifacts = [D:\projects\living\platform\commty\build\dists\commty-dev-de31042.war] Starting action 'deploy' for remote container 'wildfly10x' on 'http://localhost:9992' Container properties = [:] :deployDevWildfly10 FAILED

Otherwise, using gradle deployDevWildfly10 --debug I'm getting these messages:

08:30:20.505 [DEBUG] [sun.net.www.protocol.http.HttpURLConnection] sun.net.www.MessageHeader@5b565a527 pairs: {POST /management/add-content HTTP/1.1: null}{Connection: close}{Content-Type: multipart/form-data; boundary=CargoBoundary}{User-Agent: Java/1.8.0_45}{Host: localhost:9990}{Accept: text/html, image/gif, image/jpeg, ; q=.2, /*; q=.2}{Content-Length: 29832076} 08:30:20.627 [DEBUG] [sun.net.www.protocol.http.HttpURLConnection] sun.net.www.MessageHeader@4a857f181 pairs: {Content-type: unknown/unknown} 08:30:20.627 [DEBUG] [org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter] Finished executing task ':deployDevWildfly10' 08:30:20.627 [LIFECYCLE] [class org.gradle.internal.buildevents.TaskExecutionLogger] :deployDevWildfly10 FAILED

This is my last gradle script.

jeusdi commented 7 years ago

I've been trying it for a some days ago, and I'm not able reach my server.

Nevertheless, I'm able to log in using web interface.

Any ideas?

bmuschko commented 7 years ago

My guess is that you'll have to change the HTTP management port explicitly by a property. That's pre-set by Cargo. For more information see cargo.jboss.management-http.port under Runtime Configuration Properties.

In your task creation you'll have to assign something to the property containerProperties. Something like this (haven't tried it):

remoteContainers.each { config ->
    task "deployDev${config.name.capitalize()}"(type: com.bmuschko.gradle.cargo.tasks.remote.CargoDeployRemote) {
        containerProperties['cargo.jboss.management-http.port', 2222]
    }
}
jeusdi commented 7 years ago

Thanks @bmuschko I've added the containerProperties:

remoteContainers.each { config ->
    task "deployDev${config.name.capitalize()}"(type: com.bmuschko.gradle.cargo.tasks.remote.CargoDeployRemote) {
        description = "Deploys WAR to remote Web Application Server: '${config.name}'."
        containerId = config.container
        hostname = config.hostname
        port = config.port
        username = config.username
        password = config.password
        context = "webapi"
        dependsOn = [createDevelopmentWar]
        deployables = [new com.bmuschko.gradle.cargo.convention.Deployable(file: createDevelopmentWar.archivePath)]
        containerProperties['cargo.jboss.management-http.port', 9992]
    }

Nevertheless, I keep getting the same message:

09:37:16.667 [DEBUG] [sun.net.www.protocol.http.HttpURLConnection] sun.net.www.MessageHeader@6bcedb777 pairs: {POST /management/add-content HTTP/1.1: null}{Connection: close}{Content-Type: multipart/form-data; boundary=CargoBoundary}{User-Agent: Java/1.8.0_45}{Host: localhost:9990}{Accept: text/html, image/gif, image/jpeg, ; q=.2, /*; q=.2}{Content-Length: 29869382}

I'd like you look at cargo dependencies. Currently, I'm setting these dependencies in order to connect cargo with wildfly10:

dependencies {
    cargo 'org.wildfly:wildfly-controller-client:8.2.0.Final'
    cargo 'org.codehaus.cargo:cargo-core-uberjar:1.6.2'
    cargo 'org.codehaus.cargo:cargo-ant:1.6.2'
}

Am I using the correct dependencies in order to connect cargo with a wildfly 10 instance?

bmuschko commented 7 years ago

In that I case I do not know. I suggest you ask about this on the Cargo user mailing list.

sutaakar commented 7 years ago

I have briefly checked the management-http functionality from Codehaus Cargo side, it should work if cargo.jboss.management-http.port is set in Cargo configuration. @jeusdi Can you check if that containerProperties value is propagated all the way down to Codehaus Cargo?

jeusdi commented 7 years ago

Thanks @sutaakar for your comment.

Nevertheless, I don't quite know what you exactly mean to... I mean, I don't know how to dig into Codehaus Cargo from my gradle script... Do you mean I take a look on debug? Nevertheless, how can I get this exactly information? Are you thinking about configuring any logger?

I think the messages I get from the task execution shows ho gradle plugin is reporting me correct port:

08:38:41.235 [DEBUG] [org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter] Executing actions for task ':deployDevWildfly10'. 08:38:41.235 [INFO] [org.gradle.api.Task] Deployable artifacts = [D:\projects\living\platform\commty\build\dists\commty-dev-aefaba1-dirty.war] 08:38:41.236 [INFO] [org.gradle.api.Task] Starting action 'deploy' for remote container 'wildfly10x' on 'http://localhost:9992'

Nevertheless, it seems that it's trying to connect to 9990 instead of 9992:

08:38:42.130 [DEBUG] [sun.net.www.protocol.http.HttpURLConnection] sun.net.www.MessageHeader@78b79fc97 pairs: {POST /management/add-content HTTP/1.1: null}{Connection: close}{Content-Type: multipart/form-data; boundary=CargoBoundary}{User-Agent: Java/1.8.0_45}{Host: localhost:9990}{Accept: text/html, image/gif, image/jpeg, ; q=.2, /*; q=.2}{Content-Length: 29870112}

Sorry.

jeusdi commented 7 years ago

I meant, I'm absolutly willing to help out adquiring that information, but I don't quite how exactly get it.

Could you give me some lights?

sutaakar commented 7 years ago

@jeusdi Can you please debug your Cargo execution? If I understand correctly then this plugin should use Cargo Ant plugin. In that case every container property should be passed to Cargo core here: https://github.com/codehaus-cargo/cargo/blob/master/extensions/ant/tasks/src/main/java/org/codehaus/cargo/ant/ConfigurationElement.java#L325-L328

Can you please put a breakpoint there and check if cargo.jboss.management-http.port is passed there?

jeusdi commented 7 years ago

Is there some tutorial showing how to debug and set a breakpoint to an Ant plugin from gradle? I've been to see, how to enable debugger on gradle, nevertheless, which code do I need to debug exactly?

sutaakar commented 7 years ago

You may try to use GRADLE_OPTS, see https://discuss.gradle.org/t/how-do-you-attach-a-debugger-to-gradle-so-that-i-can-debug-it-running-a-task/7526 . This Cargo Ant plugin can be debugged as any other java application, you will probably need to import the https://github.com/codehaus-cargo/cargo/tree/master/extensions/ant/tasks to be able to properly place debug point to the class.

jeusdi commented 7 years ago

I've imported code from repository. I've set a breakpoint on line 325 Gradle is listening on 5006.

Nevertheless, breakpoint is not reached. Any ideas?

imagen

sutaakar commented 7 years ago

Put a breakpoint to https://github.com/codehaus-cargo/cargo/blob/master/core/containers/wildfly/src/main/java/org/codehaus/cargo/container/wildfly/internal/AbstractWildFlyRemoteDeployer.java#L85 . This line should definitely be reached. If it is so check the value of management port. If it is 9990 then it is default value. Try to backtrack to place where this deployer is instantiated. It is constructed with Container parameter. Container should be created using configuration, this configuration should contain property cargo.jboss.management-http.port with your custom value.

jeusdi commented 7 years ago

It's not reached! Nevertheless, debugger is attached...

imagen

sutaakar commented 7 years ago

Try to put breakpoint to constructor - line 74.

jeusdi commented 7 years ago

It's not reached :anguished:

sutaakar commented 7 years ago

Seems that java debug has to be activated differently: https://docs.gradle.org/current/dsl/org.gradle.api.tasks.JavaExec.html try to use parameter --debug-jvm

jeusdi commented 7 years ago

I'm getting this message:

Problem configuring task :deployDevWildfly10 from command line. Unknown command-line option '--debug-jvm'.

sutaakar commented 7 years ago

Hmm, from https://discuss.gradle.org/t/how-do-you-attach-a-debugger-to-gradle-so-that-i-can-debug-it-running-a-task/7526/5 it seems that it can be possible to debug if you set jvm args in gradle.properties file.

jeusdi commented 7 years ago

I've ben able to reach this code: https://github.com/codehaus-cargo/cargo/blob/master/extensions/ant/tasks/src/main/java/org/codehaus/cargo/ant/CargoTask.java#L772

As you can see on image the port is 9990, instead of 9992!

imagen

Nevertheless, getContainer() method returns a Container with this properties:

imagen

I've laso just realized 9992 value is set on cargo.servlet.port instead of on cargo.jboss.management-http.port

imagen

sutaakar commented 7 years ago

Can you please check property cargo.jboss.management-http.port in configuration properties? cargo.servlet.port property is used as port value for http communication - equals to system property jboss.http.port. cargo.jboss.management-http.port is port value for http management communication - the one we need for remote deployment.

jeusdi commented 7 years ago

Definitely, it seems cargo gradle plugin sends to cargo ant wrong values:

When addConfiguredProperty is reached, is receives this Propertys:

cargo.servlet.port = 9992

imagen

In fact, cargo.jboss.management-http.port is not added.

jeusdi commented 7 years ago

@bmuschko I think the bug is around https://github.com/bmuschko/gradle-cargo-plugin/blob/master/src/main/groovy/com/bmuschko/gradle/cargo/tasks/remote/RemoteCargoContainerTask.groovy#L85

And it seems not reached:

https://github.com/bmuschko/gradle-cargo-plugin/blob/7fe72e9c03e0c37b5777196c87427363b6ef1191/src/main/groovy/com/bmuschko/gradle/cargo/tasks/AbstractCargoContainerTask.groovy#L102

Could you take a look, please?

jeusdi commented 7 years ago

@bmuschko , could I help out with anything more?

jeusdi commented 7 years ago

@bmuschko could you give us some feedback. Do you thing it's an issue related with gradle plugin?

bmuschko commented 7 years ago

@jeusdi I might be able to have a look within the next 2 weeks but I can't promise it.

jeusdi commented 7 years ago

@bmuschko Please, sorry for asking you for it again. Nevertheless, I'm still sticking in solving that.

Nevertheless, it would be really a great work around if it was ready...

Have you been able to take a look?