google / copybara

Copybara: A tool for transforming and moving code between repositories.
Apache License 2.0
2.16k stars 263 forks source link

is it possible to migrate pending open change from source gerrit server to destination gerrit? #148

Open gayatri-kulkarni1 opened 3 years ago

gayatri-kulkarni1 commented 3 years ago

Getting below error : Task: **Querying Gerrit ('***') for active changes with hashtag 'copybara_id2299CE23BC2B96B99CEC9CC04BD6B7BE' java.lang.IllegalArgumentException: at com.google.api.client.json.JsonParser.parseValue(JsonParser.java:889) at com.google.api.client.json.JsonParser.parse(JsonParser.java:382) at com.google.api.client.json.JsonParser.parse(JsonParser.java:355) at com.google.api.client.json.JsonObjectParser.parseAndClose(JsonObjectParser.java:87) at com.google.api.client.http.HttpResponse.parseAs(HttpResponse.java:488) at com.google.copybara.git.gerritapi.GerritApiTransportImpl.execute(GerritApiTransportImpl.java:112) at com.google.copybara.git.gerritapi.GerritApiTransportImpl.get(GerritApiTransportImpl.java:66) at com.google.copybara.git.gerritapi.GerritApi.getChanges(GerritApi.java:47) at com.google.copybara.git.GerritDestination$GerritWriteHook.findActiveChange(GerritDestination.java:230) at com.google.copybara.git.GerritDestination$GerritWriteHook.generateMessageInfo(GerritDestination.java:178) at com.google.copybara.git.GitDestination$WriterImpl.write(GitDestination.java:504) at com.google.copybara.WorkflowRunHelper$ChangeMigrator.doMigrate(WorkflowRunHelper.java:703) at com.google.copybara.WorkflowRunHelper$ChangeMigrator.migrate(WorkflowRunHelper.java:402) at com.google.copybara.WorkflowMode$2.run(WorkflowMode.java:176) at com.google.copybara.Workflow.run(Workflow.java:279) at com.google.copybara.MigrateCmd.run(MigrateCmd.java:82) at com.google.copybara.MigrateCmd.run(MigrateCmd.java:60) at com.google.copybara.Main.runInternal(Main.java:244) at com.google.copybara.Main.run(Main.java:122) at com.google.copybara.Main.main(Main.java:101) Caused by: java.lang.IllegalArgumentException: expected primitive class, but got: java.util.List at com.google.api.client.util.Data.parsePrimitiveValue(Data.java:457) at com.google.api.client.json.JsonParser.parseValue(JsonParser.java:859) ... 19 more ERROR: Unexpected error (please file a bug against copybara): (java.lang.IllegalArgumentException: )

Could someone please help.

mikelalcon commented 3 years ago

I've added 5da8147 so that we can get more information on the response. Would you mind rerunning again and get the new output?

gayatri-kulkarni1 commented 3 years ago

I have rebuilt the copybara jar and re-run the command. Here is the new output -

Dec 01, 2020 12:14:56 PM com.google.copybara.Main configureLog INFO: Setting up LogManager Copybara source mover (Version: Unknown version) Task: Cleaning output directory Task: Running migrate Task: Loading config copy.bara.sky WARN: 'ref' field detected in configuration. git.gerrit_origin is deprecating its usage for submitted changes. Use git.origin instead. Task: Validating configuration Task: Getting last revision: Resolving origin reference Task: Git Origin: Initializing local repo Task: Git Destination: Fetching: refs/heads/ Task: Cleaning working directory Task: Checking out the change Task: Removing excluded origin files Task: Checking that destination_files covers all files in transform result Task: Git Destination: Checking out Task: Git Destination: Adding all files Task: Git Destination: Excluding files Task: Git Destination: Creating a local commit Task: Querying Gerrit ('') for active changes with hashtag 'copybara_id2299CE23BC2B96B99CEC9CC04BD6B7BE' java.lang.IllegalArgumentException: at com.google.api.client.json.JsonParser.parseValue(JsonParser.java:889) at com.google.api.client.json.JsonParser.parse(JsonParser.java:382) at com.google.api.client.json.JsonParser.parse(JsonParser.java:355) at com.google.api.client.json.JsonObjectParser.parseAndClose(JsonObjectParser.java:87) at com.google.api.client.http.HttpResponse.parseAs(HttpResponse.java:488) at com.google.copybara.git.gerritapi.GerritApiTransportImpl.execute(GerritApiTransportImpl.java:112) at com.google.copybara.git.gerritapi.GerritApiTransportImpl.get(GerritApiTransportImpl.java:66) at com.google.copybara.git.gerritapi.GerritApi.getChanges(GerritApi.java:47) at com.google.copybara.git.GerritDestination$GerritWriteHook.findActiveChange(GerritDestination.java:230) at com.google.copybara.git.GerritDestination$GerritWriteHook.generateMessageInfo(GerritDestination.java:178) at com.google.copybara.git.GitDestination$WriterImpl.write(GitDestination.java:504) at com.google.copybara.WorkflowRunHelper$ChangeMigrator.doMigrate(WorkflowRunHelper.java:703) at com.google.copybara.WorkflowRunHelper$ChangeMigrator.migrate(WorkflowRunHelper.java:402) at com.google.copybara.WorkflowMode$1.run(WorkflowMode.java:117) at com.google.copybara.Workflow.run(Workflow.java:279) at com.google.copybara.MigrateCmd.run(MigrateCmd.java:82) at com.google.copybara.MigrateCmd.run(MigrateCmd.java:60) at com.google.copybara.Main.runInternal(Main.java:244) at com.google.copybara.Main.run(Main.java:122) at com.google.copybara.Main.main(Main.java:101) Caused by: java.lang.IllegalArgumentException: expected primitive class, but got: java.util.List at com.google.api.client.util.Data.parsePrimitiveValue(Data.java:457) at com.google.api.client.json.JsonParser.parseValue(JsonParser.java:859) ... 19 more ERROR: Unexpected error (please file a bug against copybara): (java.lang.IllegalArgumentException: )

Config used:

core.workflow( name = "default", origin = git.gerrit_origin( url = "<>", ref = "<<commit id/SHA of open gerrit change>>", ), destination = git.gerrit_destination( url = "<>", fetch = "<>", gerrit_submit = False ), authoring = authoring.pass_thru("Default email default@default.com") )

Could you also suggest the correct configuration to be used to achieve this requirement?

mikelalcon commented 3 years ago

Based on the stacktrace, it looks like you run with the same code version:

parseValue(JsonParser.java:889)

mikelalcon commented 3 years ago

Regarding to:

is it possible to migrate pending open change from source gerrit server to destination gerrit?

Yes, it should be possible.

gayatri-kulkarni1 commented 3 years ago

Based on the stacktrace, it looks like you run with the same code version:

parseValue(JsonParser.java:889)

ohh okay. Please check the new output here:

WARN: 'ref' field detected in configuration. git.gerrit_origin is deprecating its usage for submitted changes. Use git.origin instead. Task: Querying Gerrit ('<>') for active changes with hashtag 'copybara_idEA44847DE6FA9C4FF4B81D0E1B7D68BB' ERROR: Error running Gerrit API operation https://****/changes/?q=hashtag:%22copybara_id_EA44847DE6FA9C4FF4B81D0E1B7D68BB_%22%20AND%20project:***.git%20AND%20status:NEW CAUSED BY: stream is closed

gayatri-kulkarni1 commented 3 years ago

Regarding to:

is it possible to migrate pending open change from source gerrit server to destination gerrit?

Yes, it should be possible.

Could you please provide the correct configuration that can be used to do so. Please check the config I am using.

mikelalcon commented 3 years ago

CAUSED BY: stream is closed

That seems like a different error. The original one was parsing the response. This one is about the stream being closed while receiving the response.

Regarding to:

'ref' field detected in configuration. git.gerrit_origin is deprecating its usage for submitted changes. Use git.origin instead.

git.gerrit_origin is mean to be used for migrating presubmit changes (to test them, accept changes in the other side, etc.). If you want to migrate submitted changes (Even if are coming from gerrit), use git.origin.

If you want to migrate pending changes only from specific branches, use branch field instead of ref.

gayatri-kulkarni1 commented 3 years ago

I am trying to migrate pending change from source to destination, not getting why is it querying for destination url for the pending/active changes?

Querying Gerrit ('<>') for active changes with hashtag 'copybara_idEA44847DE6FA9C4FF4B81D0E1B7D68BB' ERROR: Error running Gerrit API operation https://*/changes/?q=hashtag:%22copybara_id_EA44847DE6FA9C4FF4B81D0E1B7D68BB_%22%20AND%20project:.git%20AND%20status:NEW

mikelalcon commented 3 years ago

We look for existing changes in the destination to reuse the same destination change for the same origin change. In order to achieve that we use Gerrit hashtag.

gayatri-kulkarni1 commented 3 years ago

As the change is new for destination (its a pending change from source), it won't match any change in destination and hence not able to migrate it.

What is the solution to migrate such open pending changes to destination without this issue.

gayatri-kulkarni1 commented 3 years ago

Hi, I was able to submit the pending change from source to destination, But my requirement is not to submit but create pending change in destination. How can I do it?