Jump to content


P4Java: expose workspace type for clients

p4java jenkins

  • Please log in to reply
6 replies to this topic

#1 tlewis

tlewis

    Newbie

  • Members
  • Pip
  • 8 posts

Posted 23 November 2016 - 02:03 AM

My organization would very much like to use readonly workspaces for our Jenkins build farm. This would remove a lot of the inefficient synchronization of our db.have table between our geographically distant forwarding replicas.

However, I've noticed that the P4Java API, which the P4 Plugin makes use of, does not expose any options for the setting a client/workspace type. So I suppose I have two questions:
1. Is the P4Java API still maintained/developed by Perforce?
2. If so, would exposing the type field for clients be possible?

#2 Sambwise

Sambwise

    Advanced Member

  • Members
  • PipPipPip
  • 947 posts

Posted 23 November 2016 - 03:50 AM

The latest P4Java release is 2015.2, so it's gone almost a full year with no update.  

My approach would be to set the client type by some other mechanism and figure that the normal client commands exposed by P4Java will continue to work.  Since you generally only set a client type once, as long as you can set your clients up in advance you should be fine.  

If your Java-based tool needs to create clients, then I think your best bet would be to create some kind of simple service that does it using some other API, and have your Java-based tool call that -- you could do this as a web service, or maybe even as a trigger (e.g. use a trigger to establish a convention that all clients with a particular naming pattern should default to a certain type, and then have your tool use that pattern).

#3 tlewis

tlewis

    Newbie

  • Members
  • Pip
  • 8 posts

Posted 23 November 2016 - 11:58 PM

Thanks for the input Sambwise. Unfortunately we're relying on the P4 Plugin (which is excellent) for Jenkins to create and manage our build farm workspaces. I believe if I were to change the client spec outside of the P4 Plugin, it would be overwritten each time one of those workspaces is queried and used, thus nullifying my change to the workspace type.

#4 Sambwise

Sambwise

    Advanced Member

  • Members
  • PipPipPip
  • 947 posts

Posted 24 November 2016 - 12:31 AM

That doesn't seem intuitive to me (if the plugin doesn't know about the type it shouldn't be able to set it to a different value), but even if that's the case, you should be able to get around it with a trigger or a broker rewrite -- have the server force that any client created or modified under certain conditions (e.g. by the Jenkins user) always have the "readonly" type set before it's saved.

#5 tlewis

tlewis

    Newbie

  • Members
  • Pip
  • 8 posts

Posted 28 November 2016 - 07:22 PM

My understanding is that the plugin is completely rewriting the client spec based on the job configuration, but it's possible I'm wrong. I haven't tested it, and I should.

Your idea for a trigger that changes the type field for all clients created by our jenkins user is a good one. I'll give it a shot!

#6 tlewis

tlewis

    Newbie

  • Members
  • Pip
  • 8 posts

Posted 28 November 2016 - 10:36 PM

It appears as though my suspicion was correct: the P4Java API (and P4 Plugin) completely rewrites the client specification. I tested running a Jenkins build on a client that I had already created by hand (of Type "readonly") and I got this error when the job ran:
P4: Unable to setup workspace: com.perforce.p4java.exception.RequestException: Client storage type cannot be changed after client is created.


#7 Sambwise

Sambwise

    Advanced Member

  • Members
  • PipPipPip
  • 947 posts

Posted 29 November 2016 - 02:00 AM

View Posttlewis, on 28 November 2016 - 10:36 PM, said:

It appears as though my suspicion was correct: the P4Java API (and P4 Plugin) completely rewrites the client specification. I tested running a Jenkins build on a client that I had already created by hand (of Type "readonly") and I got this error when the job ran:
P4: Unable to setup workspace: com.perforce.p4java.exception.RequestException: Client storage type cannot be changed after client is created.

Ugh.  So yeah, will definitely need a trigger.  Luckily this is pretty much just a matter of "sed -i -e s/Type:.*/Type: readonly/ %formfile%" or something along those lines, plus the check to make sure you're only doing it for the right clients.





Also tagged with one or more of these keywords: p4java, jenkins

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users