Skip to content

Commit

Permalink
Fixes breakages of the upgrade feature (#29731)
Browse files Browse the repository at this point in the history
* Fixes breakages of the upgrade feature

* Fix spotless

* Addressing reviewer comments

* Removing unused import

* Reverting the PreCommit update
  • Loading branch information
chamikaramj authored Dec 14, 2023
1 parent 921e40a commit 4264c2c
Show file tree
Hide file tree
Showing 5 changed files with 624 additions and 521 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InvalidClassException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.ServerSocket;
Expand Down Expand Up @@ -49,12 +50,16 @@
import org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.annotations.VisibleForTesting;
import org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.base.Strings;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* A utility class that allows upgrading transforms of a given pipeline using the Beam Transform
* Service.
*/
public class TransformUpgrader implements AutoCloseable {

private static final Logger LOG = LoggerFactory.getLogger(TransformUpgrader.class);
private static final String UPGRADE_NAMESPACE = "transform:upgrade:";

private ExpansionServiceClientFactory clientFactory;
Expand Down Expand Up @@ -405,10 +410,16 @@ public static byte[] toByteArray(Object object) {
* method.
* @return re-generated object.
*/
public static Object fromByteArray(byte[] bytes) {
public static Object fromByteArray(byte[] bytes) throws InvalidClassException {
try (ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
ObjectInputStream in = new ObjectInputStream(bis)) {
return in.readObject();
} catch (InvalidClassException e) {
LOG.info(
"An object cannot be re-generated from the provided byte array. Caller may use the "
+ "default value for the parameter when upgrading. Underlying error: "
+ e);
throw e;
} catch (Exception e) {
throw new RuntimeException(e);
}
Expand Down
Loading

0 comments on commit 4264c2c

Please sign in to comment.