Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unrecognized http status code: 411 when detaching disk via InstanceClient#detachDiskInstance #3735

Closed
kitsenky opened this issue Sep 26, 2018 · 4 comments
Assignees
Labels
api: compute Issues related to the Compute Engine API. priority: p1 Important issue which blocks shipping the next release. Will be fixed prior to next release. 🚨 This issue needs some love. type: question Request for information or clarification. Not an issue.

Comments

@kitsenky
Copy link

kitsenky commented Sep 26, 2018

When 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)
@kitsenky
Copy link
Author

kitsenky commented 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()));
        }
    }

}

@JustinBeckwith JustinBeckwith added the triage me I really want to be triaged. label Sep 27, 2018
@yihanzhen yihanzhen added type: question Request for information or clarification. Not an issue. api: compute Issues related to the Compute Engine API. priority: p2 Moderately-important priority. Fix may not be included in next release. labels Sep 27, 2018
@JustinBeckwith JustinBeckwith removed the triage me I really want to be triaged. label Sep 27, 2018
@kitsenky
Copy link
Author

kitsenky commented Oct 3, 2018

It seems to be more a like bug in detach functionality of compute api v1 than a question.

@andreamlin andreamlin self-assigned this Oct 29, 2018
@cj-matti-niemenmaa
Copy link

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.

@andreamlin andreamlin added priority: p1 Important issue which blocks shipping the next release. Will be fixed prior to next release. and removed priority: p2 Moderately-important priority. Fix may not be included in next release. labels Jan 29, 2019
@yoshi-automation yoshi-automation added the 🚨 This issue needs some love. label Jan 29, 2019
@andreamlin
Copy link
Contributor

andreamlin commented 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: compute Issues related to the Compute Engine API. priority: p1 Important issue which blocks shipping the next release. Will be fixed prior to next release. 🚨 This issue needs some love. type: question Request for information or clarification. Not an issue.
Projects
None yet
Development

No branches or pull requests

6 participants