use of com.google.api.client.googleapis.json.GoogleJsonResponseException in project cloudbreak by hortonworks.
the class GcpNetworkResourceBuilder method delete.
@Override
public CloudResource delete(GcpContext context, AuthenticatedContext auth, CloudResource resource, Network network) throws Exception {
if (!isExistingNetwork(network)) {
Compute compute = context.getCompute();
String projectId = context.getProjectId();
try {
Operation operation = compute.networks().delete(projectId, resource.getName()).execute();
return createOperationAwareCloudResource(resource, operation);
} catch (GoogleJsonResponseException e) {
exceptionHandler(e, resource.getName(), resourceType());
return null;
}
}
return null;
}
use of com.google.api.client.googleapis.json.GoogleJsonResponseException in project cloudbreak by hortonworks.
the class GcpSubnetResourceBuilder method build.
@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();
}
use of com.google.api.client.googleapis.json.GoogleJsonResponseException in project cloudbreak by hortonworks.
the class AbstractGcpResourceBuilder method check.
protected Operation check(GcpContext context, DynamicModel resource) throws IOException {
String operation = resource.getStringParameter(OPERATION_ID);
if (operation == null) {
return null;
}
try {
Operation execute = GcpStackUtil.globalOperations(context.getCompute(), context.getProjectId(), operation).execute();
checkError(execute);
return execute;
} catch (GoogleJsonResponseException e) {
if (e.getDetails().get("code").equals(HttpStatus.SC_NOT_FOUND) || e.getDetails().get("code").equals(HttpStatus.SC_FORBIDDEN)) {
Location location = context.getLocation();
try {
Operation execute = GcpStackUtil.regionOperations(context.getCompute(), context.getProjectId(), operation, location.getRegion()).execute();
checkError(execute);
return execute;
} catch (GoogleJsonResponseException e1) {
if (e1.getDetails().get("code").equals(HttpStatus.SC_NOT_FOUND) || e1.getDetails().get("code").equals(HttpStatus.SC_FORBIDDEN)) {
Operation execute = GcpStackUtil.zoneOperations(context.getCompute(), context.getProjectId(), operation, location.getAvailabilityZone()).execute();
checkError(execute);
return execute;
} else {
throw e1;
}
}
} else {
throw e;
}
}
}
use of com.google.api.client.googleapis.json.GoogleJsonResponseException in project cloudbreak by hortonworks.
the class GcpReservedIpResourceBuilder method build.
@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;
}
use of com.google.api.client.googleapis.json.GoogleJsonResponseException in project cloudbreak by hortonworks.
the class GcpFirewallInResourceBuilder method build.
@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;
firewallRequest = StringUtils.isNotBlank(security.getCloudSecurityId()) && isExistingNetwork(network) ? updateExistingFirewallForNewTargets(context, auth, group, security) : 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());
}
}
Aggregations