本文整理汇总了Java中com.google.api.services.compute.model.Operation.getHttpErrorMessage方法的典型用法代码示例。如果您正苦于以下问题:Java Operation.getHttpErrorMessage方法的具体用法?Java Operation.getHttpErrorMessage怎么用?Java Operation.getHttpErrorMessage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.api.services.compute.model.Operation
的用法示例。
在下文中一共展示了Operation.getHttpErrorMessage方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: build
import com.google.api.services.compute.model.Operation; //导入方法依赖的package包/类
@Override
public CloudResource build(GcpContext context, AuthenticatedContext auth, Network network, Security security, CloudResource resource) throws Exception {
if (!isExistingNetwork(network)) {
Compute compute = context.getCompute();
String projectId = context.getProjectId();
com.google.api.services.compute.model.Network gcpNetwork = new com.google.api.services.compute.model.Network();
gcpNetwork.setName(resource.getName());
gcpNetwork.setAutoCreateSubnetworks(false);
Insert networkInsert = compute.networks().insert(projectId, gcpNetwork);
try {
Operation operation = networkInsert.execute();
if (operation.getHttpErrorStatusCode() != null) {
throw new GcpResourceException(operation.getHttpErrorMessage(), resourceType(), resource.getName());
}
context.putParameter(NETWORK_NAME, resource.getName());
return createOperationAwareCloudResource(resource, operation);
} catch (GoogleJsonResponseException e) {
throw new GcpResourceException(checkException(e), resourceType(), resource.getName());
}
}
context.putParameter(NETWORK_NAME, resource.getName());
return new Builder().cloudResource(resource).persistent(false).build();
}
示例2: build
import com.google.api.services.compute.model.Operation; //导入方法依赖的package包/类
@Override
public CloudResource build(GcpContext context, AuthenticatedContext auth, Group group, Network network, Security security, CloudResource buildableResource)
throws Exception {
String projectId = context.getProjectId();
ComputeRequest<Operation> firewallRequest;
if (StringUtils.isNotBlank(security.getCloudSecurityId()) && isExistingNetwork(network)) {
firewallRequest = updateExistingFirewallForNewTargets(context, auth, group, security);
} else {
firewallRequest = createNewFirewallRule(context, auth, group, security, buildableResource, projectId);
}
try {
Operation operation = firewallRequest.execute();
if (operation.getHttpErrorStatusCode() != null) {
throw new GcpResourceException(operation.getHttpErrorMessage(), resourceType(), buildableResource.getName());
}
return createOperationAwareCloudResource(buildableResource, operation);
} catch (GoogleJsonResponseException e) {
throw new GcpResourceException(checkException(e), resourceType(), buildableResource.getName());
}
}
示例3: build
import com.google.api.services.compute.model.Operation; //导入方法依赖的package包/类
@Override
public List<CloudResource> build(GcpContext context, long privateId, AuthenticatedContext auth, Group group, Image image,
List<CloudResource> buildableResources, Map<String, String> tags) throws Exception {
String projectId = context.getProjectId();
Location location = context.getLocation();
Disk disk = new Disk();
disk.setSizeGb(DEFAULT_ROOT_DISK_SIZE);
disk.setName(buildableResources.get(0).getName());
disk.setKind(GcpDiskType.HDD.getUrl(projectId, location.getAvailabilityZone()));
Map<String, String> customTags = new HashMap<>();
customTags.putAll(tags);
customTags.putAll(defaultCostTaggingService.prepareDiskTagging());
disk.setLabels(customTags);
Insert insDisk = context.getCompute().disks().insert(projectId, location.getAvailabilityZone().value(), disk);
insDisk.setSourceImage(GcpStackUtil.getAmbariImage(projectId, image.getImageName()));
try {
Operation operation = insDisk.execute();
if (operation.getHttpErrorStatusCode() != null) {
throw new GcpResourceException(operation.getHttpErrorMessage(), resourceType(), buildableResources.get(0).getName());
}
return Collections.singletonList(createOperationAwareCloudResource(buildableResources.get(0), operation));
} catch (GoogleJsonResponseException e) {
throw new GcpResourceException(checkException(e), resourceType(), buildableResources.get(0).getName());
}
}
示例4: build
import com.google.api.services.compute.model.Operation; //导入方法依赖的package包/类
@Override
public List<CloudResource> build(GcpContext context, long privateId, AuthenticatedContext auth, Group group, Image image,
List<CloudResource> buildableResource, Map<String, String> tags) throws Exception {
List<CloudResource> result = buildableResource;
if (!buildableResource.isEmpty()) {
CloudResource resource = buildableResource.get(0);
String projectId = context.getProjectId();
String region = context.getLocation().getRegion().value();
Address address = new Address();
address.setName(resource.getName());
Map<String, String> customTags = new HashMap<>();
customTags.putAll(tags);
customTags.putAll(defaultCostTaggingService.prepareIpTagging());
address.setLabels(customTags);
Insert networkInsert = context.getCompute().addresses().insert(projectId, region, address);
try {
Operation operation = networkInsert.execute();
if (operation.getHttpErrorStatusCode() != null) {
throw new GcpResourceException(operation.getHttpErrorMessage(), resourceType(), resource.getName());
}
result = Collections.singletonList(createOperationAwareCloudResource(resource, operation));
} catch (GoogleJsonResponseException e) {
throw new GcpResourceException(checkException(e), resourceType(), resource.getName());
}
}
return result;
}
示例5: build
import com.google.api.services.compute.model.Operation; //导入方法依赖的package包/类
@Override
public CloudResource build(GcpContext context, AuthenticatedContext auth, Network network, Security security, CloudResource resource) throws Exception {
if (isNewNetworkAndSubnet(network) || isNewSubnetInExistingNetwork(network)) {
Compute compute = context.getCompute();
String projectId = context.getProjectId();
Subnetwork gcpSubnet = new Subnetwork();
gcpSubnet.setName(resource.getName());
gcpSubnet.setIpCidrRange(network.getSubnet().getCidr());
String networkName = context.getStringParameter(GcpNetworkResourceBuilder.NETWORK_NAME);
gcpSubnet.setNetwork(String.format("https://www.googleapis.com/compute/v1/projects/%s/global/networks/%s", projectId, networkName));
Insert snInsert = compute.subnetworks().insert(projectId, auth.getCloudContext().getLocation().getRegion().value(), gcpSubnet);
try {
Operation operation = snInsert.execute();
if (operation.getHttpErrorStatusCode() != null) {
throw new GcpResourceException(operation.getHttpErrorMessage(), resourceType(), resource.getName());
}
context.putParameter(SUBNET_NAME, resource.getName());
return createOperationAwareCloudResource(resource, operation);
} catch (GoogleJsonResponseException e) {
throw new GcpResourceException(checkException(e), resourceType(), resource.getName());
}
}
context.putParameter(SUBNET_NAME, resource.getName());
return new Builder().cloudResource(resource).persistent(false).build();
}
示例6: deleteNetwork
import com.google.api.services.compute.model.Operation; //导入方法依赖的package包/类
@AfterSuite
@Parameters("vpcName")
public void deleteNetwork(@Optional("it-vpc") String vpcName) throws Exception {
springTestContextPrepareTestInstance();
String serviceAccountPrivateKey = ResourceUtil.readBase64EncodedContentFromResource(applicationContext, defaultP12File);
HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport();
PrivateKey privateKey = SecurityUtils.loadPrivateKeyFromKeyStore(SecurityUtils.getPkcs12KeyStore(),
new ByteArrayInputStream(Base64.decodeBase64(serviceAccountPrivateKey)), "notasecret", "privatekey", "notasecret");
JacksonFactory jsonFactory = JacksonFactory.getDefaultInstance();
GoogleCredential googleCredential = new GoogleCredential.Builder().setTransport(httpTransport)
.setJsonFactory(jsonFactory)
.setServiceAccountId(defaultServiceAccountId)
.setServiceAccountScopes(Collections.singletonList(ComputeScopes.COMPUTE))
.setServiceAccountPrivateKey(privateKey)
.build();
Compute compute = new Builder(httpTransport, jsonFactory, null)
.setApplicationName(defaultName)
.setHttpRequestInitializer(googleCredential)
.build();
Delete delete = compute.networks().delete(defaultProjectId, vpcName);
Operation operation = delete.execute();
if (operation.getHttpErrorStatusCode() != null) {
throw new IllegalStateException("gcp operation failed: " + operation.getHttpErrorMessage());
}
}
示例7: build
import com.google.api.services.compute.model.Operation; //导入方法依赖的package包/类
@Override
public CloudResource build(GcpContext context, AuthenticatedContext auth, Network network, Security security, CloudResource buildableResource)
throws Exception {
String projectId = context.getProjectId();
Firewall firewall = new Firewall();
Allowed allowed1 = new Allowed();
allowed1.setIPProtocol("tcp");
allowed1.setPorts(Collections.singletonList("1-65535"));
Allowed allowed2 = new Allowed();
allowed2.setIPProtocol("icmp");
Allowed allowed3 = new Allowed();
allowed3.setIPProtocol("udp");
allowed3.setPorts(Collections.singletonList("1-65535"));
firewall.setTargetTags(Collections.singletonList(GcpStackUtil.getClusterTag(auth.getCloudContext())));
firewall.setAllowed(Arrays.asList(allowed1, allowed2, allowed3));
firewall.setName(buildableResource.getName());
if (isLegacyNetwork(network)) {
Networks.Get networkRequest = context.getCompute().networks().get(projectId, getCustomNetworkId(network));
com.google.api.services.compute.model.Network existingNetwork = networkRequest.execute();
firewall.setSourceRanges(Collections.singletonList(existingNetwork.getIPv4Range()));
} else if (isNewNetworkAndSubnet(network) || isNewSubnetInExistingNetwork(network)) {
firewall.setSourceRanges(Collections.singletonList(network.getSubnet().getCidr()));
} else {
Get sn = context.getCompute().subnetworks().get(projectId, context.getLocation().getRegion().value(), getSubnetId(network));
com.google.api.services.compute.model.Subnetwork existingSubnet = sn.execute();
firewall.setSourceRanges(Collections.singletonList(existingSubnet.getIpCidrRange()));
}
firewall.setNetwork(String.format("https://www.googleapis.com/compute/v1/projects/%s/global/networks/%s", projectId,
context.getParameter(GcpNetworkResourceBuilder.NETWORK_NAME, String.class)));
Insert firewallInsert = context.getCompute().firewalls().insert(projectId, firewall);
try {
Operation operation = firewallInsert.execute();
if (operation.getHttpErrorStatusCode() != null) {
throw new GcpResourceException(operation.getHttpErrorMessage(), resourceType(), buildableResource.getName());
}
return createOperationAwareCloudResource(buildableResource, operation);
} catch (GoogleJsonResponseException e) {
throw new GcpResourceException(checkException(e), resourceType(), buildableResource.getName());
}
}
示例8: createNetwork
import com.google.api.services.compute.model.Operation; //导入方法依赖的package包/类
@Test
@Parameters({"networkName", "description", "publicInAccount", "resourceGroupName", "vpcName", "vpcSubnet", "subnetCIDR", "networkType"})
public void createNetwork(String networkName, @Optional("") String description, @Optional("false") boolean publicInAccount,
@Optional("europe-west1") String subnetRegion, @Optional("it-vpc") String vpcName,
@Optional("it-vpc-subnet") String vpcSubnet, @Optional("10.0.36.0/24") String subnetCIDR, NetworkType networkType) throws Exception {
String serviceAccountPrivateKey = ResourceUtil.readBase64EncodedContentFromResource(applicationContext, defaultP12File);
HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport();
PrivateKey privateKey = SecurityUtils.loadPrivateKeyFromKeyStore(SecurityUtils.getPkcs12KeyStore(),
new ByteArrayInputStream(Base64.decodeBase64(serviceAccountPrivateKey)), "notasecret", "privatekey", "notasecret");
JacksonFactory jsonFactory = JacksonFactory.getDefaultInstance();
GoogleCredential googleCredential = new GoogleCredential.Builder().setTransport(httpTransport)
.setJsonFactory(jsonFactory)
.setServiceAccountId(defaultServiceAccountId)
.setServiceAccountScopes(Collections.singletonList(ComputeScopes.COMPUTE))
.setServiceAccountPrivateKey(privateKey)
.build();
Compute compute = new Builder(httpTransport, jsonFactory, null)
.setApplicationName(defaultName)
.setHttpRequestInitializer(googleCredential)
.build();
Network gcpNetwork = new Network();
gcpNetwork.setName(vpcName);
if (!LAGACY_NETWORK.equals(networkType)) {
gcpNetwork.setAutoCreateSubnetworks(false);
}
Networks.Insert networkInsert = compute.networks().insert(defaultProjectId, gcpNetwork);
Operation networkInsertResponse = networkInsert.execute();
if (networkInsertResponse.getHttpErrorStatusCode() != null) {
throw new IllegalStateException("gcp network operation failed: " + networkInsertResponse.getHttpErrorMessage());
}
waitOperation(compute, networkInsertResponse);
if (EXISTING_SUBNET_IN_EXISTING_NETWORK.equals(networkType)) {
Subnetwork gcpSubnet = new Subnetwork();
gcpSubnet.setName(vpcSubnet);
gcpSubnet.setIpCidrRange(subnetCIDR);
gcpSubnet.setNetwork(String.format("https://www.googleapis.com/compute/v1/projects/%s/global/networks/%s", defaultProjectId, vpcName));
Insert subNetworkInsert = compute.subnetworks().insert(defaultProjectId, subnetRegion, gcpSubnet);
Operation subNetInsertResponse = subNetworkInsert.execute();
if (subNetInsertResponse.getHttpErrorStatusCode() != null) {
throw new IllegalStateException("gcp subnetwork operation failed: " + subNetInsertResponse.getHttpErrorMessage());
}
}
NetworkRequest networkRequest = new NetworkRequest();
networkRequest.setName(networkName);
networkRequest.setDescription(description);
if (NEW_SUBNET_IN_EXISTING_NETWORK.equals(networkType)) {
networkRequest.setSubnetCIDR(subnetCIDR);
}
Map<String, Object> map = new HashMap<>();
map.put("networkId", vpcName);
if (EXISTING_SUBNET_IN_EXISTING_NETWORK.equals(networkType)) {
map.put("subnetId", vpcSubnet);
}
networkRequest.setParameters(map);
networkRequest.setCloudPlatform("GCP");
String id = getCloudbreakClient().networkEndpoint().postPrivate(networkRequest).getId().toString();
getItContext().putContextParam(CloudbreakITContextConstants.NETWORK_ID, id, true);
}