-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Closed
Labels
api: computeIssues related to the Compute Engine API.Issues related to the Compute Engine API.priority: p1Important issue which blocks shipping the next release. Will be fixed prior to next release.Important issue which blocks shipping the next release. Will be fixed prior to next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Description
- google-cloud-java version: 0.79-alpha
Steps to reproduce
The recent changes linked to #3604 have caused that Compute SDK usage has become more complicated. Let take a look on the following examples.
Code snippet
Before:
val machineType = ProjectZoneMachineTypeName.of(machineType, myProjectId, zone).toString()
val instance = Instance.newBuilder().setMachineType(machineType).build()
instanceClient.insertInstance(instance)After #3604 ResourceName.toString() methods does not append projects/ prefix anymore and as result the previous code fragment fails with exceptions like that because they're required by REST APIs:
Caused by: com.google.api.client.http.HttpResponseException: 400 Bad Request
{
"error": {
"errors": [
{
"domain": "global",
"reason": "invalid",
"message": "Invalid value for field 'resource.machineType': 'project-123/zones/europe-west3-b/machineTypes/n1-standard-1'. The URL is malformed."
},
{
"domain": "global",
"reason": "invalid",
"message": "Invalid value for field 'resource.disks[0].initializeParams.sourceImage': 'project-123/global/images/image-name'. The URL is malformed."
}
],
"code": 400,
"message": "Invalid value for field 'resource.machineType': 'project-123/zones/europe-west3-b/machineTypes/n1-standard-1'. The URL is malformed."
}
}To resolve it for each ResourceName should be added ResourceName.SERVICE_ADDRESS prefix like that:
val machineType = ProjectZoneMachineTypeName.SERVICE_ADDRESS +
ProjectZoneMachineTypeName.of(machineType, myProjectId, zone).toString()
val instance = Instance.newBuilder().setMachineType(machineType).build()
instanceClient.insertInstance(instance)Metadata
Metadata
Assignees
Labels
api: computeIssues related to the Compute Engine API.Issues related to the Compute Engine API.priority: p1Important issue which blocks shipping the next release. Will be fixed prior to next release.Important issue which blocks shipping the next release. Will be fixed prior to next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.Error or flaw in code with unintended results or allowing sub-optimal usage patterns.