GeezerVison is showing github.com — Unrecognized http status code: 411 when detaching disk via InstanceClient#detachDiskInstance · Issue #3735 · googleapis/google-cloud-java
Unrecognized http status code: 411 when detaching disk via InstanceClient#detachDiskInstance #3735Labels 🚨 criticalP0 critical issue. Requires immediate fixapi: computeIssues related to the Compute Engine API.priority: p1Important issue which blocks shipping the next release. Will be fixed prior to next release.type: questionRequest for information or clarification. Not an issue. DescriptionWhen trying to detach disk via InstanceClient#detachDiskInstance the operation fails with the stacktrace
Sep 26, 2018 10:51:28 PM com.google.common.util.concurrent.AbstractFuture executeListener
SEVERE: RuntimeException while executing runnable com.google.common.util.concurrent.Futures$4@7b8f7c5c with executor MoreExecutors.directExecutor()
java.lang.IllegalArgumentException: Unrecognized http status code: 411
at com.google.api.gax.httpjson.HttpJsonStatusCode.httpStatusToStatusCode(HttpJsonStatusCode.java:102)
at com.google.api.gax.httpjson.HttpJsonExceptionCallable$ExceptionTransformingFuture.onFailure(HttpJsonExceptionCallable.java:99)
at com.google.api.core.ApiFutures$1.onFailure(ApiFutures.java:68)
at com.google.common.util.concurrent.Futures$4.run(Futures.java:1123)
at com.google.common.util.concurrent.MoreExecutors$DirectExecutor.execute(MoreExecutors.java:435)
at com.google.common.util.concurrent.AbstractFuture.executeListener(AbstractFuture.java:900)
at com.google.common.util.concurrent.AbstractFuture.complete(AbstractFuture.java:811)
at com.google.common.util.concurrent.AbstractFuture.setException(AbstractFuture.java:675)
at com.google.api.core.AbstractApiFuture$InternalSettableFuture.setException(AbstractApiFuture.java:95)
at com.google.api.core.AbstractApiFuture.setException(AbstractApiFuture.java:77)
at com.google.api.core.SettableApiFuture.setException(SettableApiFuture.java:52)
at com.google.api.gax.httpjson.HttpRequestRunnable.run(HttpRequestRunnable.java:145)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748) Activitykitsenky commented on Sep 27, 2018 Actually every usage of InstanceClient#detachDiskInstance fails. Here is example of code that fails:
import com.google.cloud.compute.v1.AttachedDiskInitializeParams;
import com.google.cloud.compute.v1.Disk;
import com.google.cloud.compute.v1.DiskClient;
import com.google.cloud.compute.v1.Instance;
import com.google.cloud.compute.v1.InstanceClient;
import com.google.cloud.compute.v1.NetworkInterface;
import com.google.cloud.compute.v1.Operation;
import com.google.cloud.compute.v1.ProjectGlobalImageName;
import com.google.cloud.compute.v1.ProjectGlobalNetworkName;
import com.google.cloud.compute.v1.ProjectRegionSubnetworkName;
import com.google.cloud.compute.v1.ProjectZoneDiskName;
import com.google.cloud.compute.v1.ProjectZoneDiskTypeName;
import com.google.cloud.compute.v1.ProjectZoneInstanceName;
import com.google.cloud.compute.v1.ProjectZoneMachineTypeName;
import com.google.cloud.compute.v1.ProjectZoneName;
import java.io.IOException;
import java.util.UUID;
public class NewApiExample {
private static String PROJECT = "YOUR_PROGECT";
private static String REGION = "us-west1";
private static String ZONE = "us-west1-a";
private static String NETWORK = "YOUR_NETWORK";
private static String SUBNET = "YOUR_SUBNETWORK";
private static String IMAGE = "YOUR_UBUNTU_IMAGE";
public static void main(String[] args) throws InterruptedException {
String uuid = UUID.randomUUID().toString();
long startAt =System.currentTimeMillis();
try (InstanceClient instanceClient = InstanceClient.create(); DiskClient diskClient = DiskClient.create()) {
System.out.println("Clients created in " + (System.currentTimeMillis() - startAt) + "ms.");
ProjectZoneName zone = ProjectZoneName.of(PROJECT, ZONE);
ProjectZoneMachineTypeName machineTypeName = ProjectZoneMachineTypeName
.of(String.format("custom-%s-%s", 4, 4 * 1024), PROJECT, ZONE);
ProjectGlobalNetworkName networkName = ProjectGlobalNetworkName.of(NETWORK, PROJECT);
ProjectRegionSubnetworkName subnetworkName = ProjectRegionSubnetworkName
.of(PROJECT, REGION, SUBNET);
ProjectGlobalImageName imageName = ProjectGlobalImageName.of(IMAGE, PROJECT);
NetworkInterface networkInterface = NetworkInterface.newBuilder()
.setNetwork(networkName.toString())
.setSubnetwork(subnetworkName.toString())
.build();
AttachedDisk bootDisk = AttachedDisk.newBuilder()
.setAutoDelete(true)
.setBoot(true)
.setInitializeParams(AttachedDiskInitializeParams.newBuilder()
.setSourceImage(imageName.toString())
.setDiskSizeGb(String.valueOf(25))
.build())
.build();
ProjectZoneInstanceName instanceName = ProjectZoneInstanceName
.of(String.format("test-api-instance-%s", uuid), PROJECT, ZONE);
Instance instanceResource = Instance.newBuilder()
.setName(instanceName.getInstance())
.addNetworkInterfaces(networkInterface)
.setMachineType(machineTypeName.toString())
.addDisks(bootDisk)
.build();
Operation op1 = instanceClient.insertInstance(zone, instanceResource);
System.out.println(String.format("Instance created: %s", op1.toString()));
ProjectZoneDiskTypeName diskTypeName = ProjectZoneDiskTypeName.of("pd-standard", PROJECT, ZONE);
ProjectZoneDiskName diskName = ProjectZoneDiskName
.of(String.format("test-api-device-name-%s", uuid), PROJECT, ZONE);
Disk disk = Disk.newBuilder()
.setName(diskName.getDisk())
.setSizeGb(String.valueOf(7))
.setType(diskTypeName.toString())
.build();
Operation op2 = diskClient.insertDisk(zone, disk);
System.out.println(String.format("Disk created: %s", op2.toString()));
Thread.sleep(10000);
AttachedDisk attachedDisk = AttachedDisk.newBuilder()
.setDeviceName(diskName.getDisk())
.setAutoDelete(false)
.setMode("READ_WRITE")
.setSource(diskName.toString())
.build();
Operation op3 = instanceClient.attachDiskInstance(instanceName, false, attachedDisk);
System.out.println(String.format("Disk attached: %s", op3.toString()));
Thread.sleep(10000);
System.out.println("----------------------------------------");
System.out.println(String.format(
"After getting error you should manually delete instance %s and disk %s",
instanceName.getInstance(),
diskName.getDisk()
));
System.out.println("----------------------------------------");
//This operation fails
Operation op4 = instanceClient.detachDiskInstance(instanceName, diskName.getDisk());
System.out.println(String.format("Disk detached: %s", op4.toString()));
} catch (IOException ex) {
System.out.println(String.format("Error when creating clients %s", ex.getMessage()));
}
}
}
kitsenky commented on Oct 3, 2018 It seems to be more a like bug in detach functionality of compute api v1 than a question. cj-matti-niemenmaa commented on Jan 28, 2019 The problem noted at JetBrains/teamcity-google-agent#27 (comment) seems to be the same thing, but with stopInstance. The commonality is that both are POST requests with an empty request body. Presumably, in such a case, the underlying HTTP client doesn't set the Content-Length header at all whereas the server requires it. added priority: p1Important issue which blocks shipping the next release. Will be fixed prior to next release. and removed priority: p2Moderately-important priority. Fix may not be included in next release. on Jan 29, 2019andreamlin commented on Jan 29, 2019 ack.
Fix is probably just adding the content-length header to all requests. This fix will be added to the gax-java dependency.
Thanks for triaging @matti-cujo
MetadataMetadata🚨 criticalP0 critical issue. Requires immediate fixapi: computeIssues related to the Compute Engine API.priority: p1Important issue which blocks shipping the next release. Will be fixed prior to next release.type: questionRequest for information or clarification. Not an issue. DevelopmentNo branches or pull requestsIssue actions
|