本文整理汇总了Java中com.google.api.services.compute.model.Operation类的典型用法代码示例。如果您正苦于以下问题:Java Operation类的具体用法?Java Operation怎么用?Java Operation使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Operation类属于com.google.api.services.compute.model包,在下文中一共展示了Operation类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: stopStart
import com.google.api.services.compute.model.Operation; //导入依赖的package包/类
private CloudVmInstanceStatus stopStart(GcpContext context, AuthenticatedContext auth, CloudInstance instance, boolean stopRequest) {
String projectId = GcpStackUtil.getProjectId(auth.getCloudCredential());
String availabilityZone = context.getLocation().getAvailabilityZone().value();
Compute compute = context.getCompute();
String instanceId = instance.getInstanceId();
try {
Get get = compute.instances().get(projectId, availabilityZone, instanceId);
String state = stopRequest ? "RUNNING" : "TERMINATED";
if (state.equals(get.execute().getStatus())) {
Operation operation = stopRequest ? compute.instances().stop(projectId, availabilityZone, instanceId).setPrettyPrint(true).execute()
: compute.instances().start(projectId, availabilityZone, instanceId).setPrettyPrint(true).execute();
CloudInstance operationAwareCloudInstance = createOperationAwareCloudInstance(instance, operation);
return checkInstances(context, auth, Collections.singletonList(operationAwareCloudInstance)).get(0);
} else {
LOGGER.info("Instance {} is not in {} state - won't start it.", state, instanceId);
return null;
}
} catch (IOException e) {
throw new GcpResourceException(String.format("An error occurred while stopping the vm '%s'", instanceId), e);
}
}
示例2: 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();
}
示例3: 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());
}
}
示例4: createNewFirewallRule
import com.google.api.services.compute.model.Operation; //导入依赖的package包/类
private ComputeRequest<Operation> createNewFirewallRule(GcpContext context, AuthenticatedContext auth, Group group, Security security,
CloudResource buildableResource, String projectId) throws IOException {
ComputeRequest<Operation> firewallRequest;
List<String> sourceRanges = getSourceRanges(security);
Firewall firewall = new Firewall();
firewall.setSourceRanges(sourceRanges);
List<Allowed> allowedRules = new ArrayList<>();
allowedRules.add(new Allowed().setIPProtocol("icmp"));
allowedRules.addAll(createRule(security));
firewall.setTargetTags(Collections.singletonList(GcpStackUtil.getGroupClusterTag(auth.getCloudContext(), group)));
firewall.setAllowed(allowedRules);
firewall.setName(buildableResource.getName());
firewall.setNetwork(String.format("https://www.googleapis.com/compute/v1/projects/%s/global/networks/%s",
projectId, context.getParameter(GcpNetworkResourceBuilder.NETWORK_NAME, String.class)));
return context.getCompute().firewalls().insert(projectId, firewall);
}
示例5: update
import com.google.api.services.compute.model.Operation; //导入依赖的package包/类
@Override
public CloudResourceStatus update(GcpContext context, AuthenticatedContext auth, Group group, Network network, Security security, CloudResource resource) {
String projectId = context.getProjectId();
Compute compute = context.getCompute();
String resourceName = resource.getName();
try {
Firewall fireWall = compute.firewalls().get(projectId, resourceName).execute();
List<String> sourceRanges = getSourceRanges(security);
fireWall.setSourceRanges(sourceRanges);
Operation operation = compute.firewalls().update(projectId, resourceName, fireWall).execute();
CloudResource cloudResource = createOperationAwareCloudResource(resource, operation);
return checkResources(context, auth, Collections.singletonList(cloudResource)).get(0);
} catch (IOException e) {
throw new GcpResourceException("Failed to update resource!", GCP_FIREWALL_IN, resourceName, e);
}
}
示例6: checkResources
import com.google.api.services.compute.model.Operation; //导入依赖的package包/类
protected List<CloudResourceStatus> checkResources(ResourceType type, GcpContext context, AuthenticatedContext auth, List<CloudResource> resources) {
List<CloudResourceStatus> result = new ArrayList<>();
for (CloudResource resource : resources) {
LOGGER.info("Check {} resource: {}", type, resource);
try {
Operation operation = check(context, resource);
boolean finished = operation == null || GcpStackUtil.isOperationFinished(operation);
ResourceStatus successStatus = context.isBuild() ? ResourceStatus.CREATED : ResourceStatus.DELETED;
result.add(new CloudResourceStatus(resource, finished ? successStatus : ResourceStatus.IN_PROGRESS));
if (finished) {
if (successStatus == ResourceStatus.CREATED) {
LOGGER.info("Creation of {} was successful", resource);
} else {
LOGGER.info("Deletion of {} was successful", resource);
}
}
} catch (Exception e) {
CloudContext cloudContext = auth.getCloudContext();
throw new GcpResourceException("Error during status check", type,
cloudContext.getName(), cloudContext.getId(), resource.getName(), e);
}
}
return result;
}
示例7: waitOperation
import com.google.api.services.compute.model.Operation; //导入依赖的package包/类
private void waitOperation(Compute compute, Operation operation) throws java.io.IOException {
int tried = 0;
while (tried < MAX_TRY) {
LOGGER.info("check operation: " + operation.getName() + ", tried: " + tried);
Operation checkResponse = compute.globalOperations().get(defaultProjectId, operation.getName()).execute();
if ("DONE".equals(checkResponse.getStatus())) {
break;
}
tried++;
try {
Thread.sleep(10000);
} catch (InterruptedException e) {
LOGGER.error("thread sleep interrupted", e);
}
}
if (tried == MAX_TRY) {
throw new RuntimeException("wait for operation exceeded maximum retry number, operation: " + operation.getName());
}
}
示例8: deleteInstance
import com.google.api.services.compute.model.Operation; //导入依赖的package包/类
private static Operation deleteInstance(Compute compute, String instanceName) throws Exception {
System.out.println(
"================== Deleting Instance " + instanceName + " ==================");
Compute.Instances.Delete delete =
compute.instances().delete(PROJECT_ID, ZONE_NAME, instanceName);
return delete.execute();
}
示例9: main
import com.google.api.services.compute.model.Operation; //导入依赖的package包/类
public static void main(String[] args) throws GeneralSecurityException, IOException {
Compute api = computeApiClient();
InstanceGroupManager group = api.regionInstanceGroupManagers().get(project, region, instanceGroup).execute();
LOG.debug("instance group found: {}", group.getInstanceGroup());
Operation operation = api.regionInstanceGroupManagers().resize(project, region, instanceGroup, targetSize)
.execute();
LOG.debug("requested resize: {}", JsonUtils.toPrettyString(JsonUtils.toJson(operation)));
}
示例10: setMetadata
import com.google.api.services.compute.model.Operation; //导入依赖的package包/类
@Override
public Operation setMetadata(String instanceUrl, Metadata metadata) throws GceException {
ensureConfigured();
InstanceUrl url = new InstanceUrl(instanceUrl);
try {
return this.apiClient.instances().setMetadata(url.getProject(), url.getZone(), url.getName(), metadata)
.execute();
} catch (IOException e) {
throw GceErrors.wrap(String.format("unable to set metadata for instance %s in project %s: %s",
url.getName(), url.getProject(), e.getMessage()), e);
}
}
示例11: resize
import com.google.api.services.compute.model.Operation; //导入依赖的package包/类
@Override
public Operation resize(int targetSize) throws GceException {
try {
return this.apiClient.instanceGroupManagers()
.resize(this.group.getProject(), this.group.getZone(), this.group.getName(), targetSize).execute();
} catch (IOException e) {
throw GceErrors.wrap(String.format(
"failed to resize instance group %s in project %s and zone %s to size %d: %s", this.group.getName(),
this.group.getProject(), this.group.getZone(), targetSize, e.getMessage()), e);
}
}
示例12: deleteInstances
import com.google.api.services.compute.model.Operation; //导入依赖的package包/类
@Override
public Operation deleteInstances(List<String> instanceUrls) {
try {
InstanceGroupManagersDeleteInstancesRequest deleteRequest = new InstanceGroupManagersDeleteInstancesRequest()
.setInstances(instanceUrls);
return this.apiClient.instanceGroupManagers()
.deleteInstances(this.group.getProject(), this.group.getZone(), this.group.getName(), deleteRequest)
.execute();
} catch (IOException e) {
throw GceErrors.wrap(String.format(
"failed to delete instances %s from instance group %s in project %s and zone %s: %s", instanceUrls,
this.group.getName(), this.group.getProject(), this.group.getZone(), e.getMessage()), e);
}
}
示例13: abandonInstances
import com.google.api.services.compute.model.Operation; //导入依赖的package包/类
@Override
public Operation abandonInstances(List<String> instanceUrls) throws GceException {
try {
InstanceGroupManagersAbandonInstancesRequest abandonRequest = new InstanceGroupManagersAbandonInstancesRequest()
.setInstances(instanceUrls);
return this.apiClient.instanceGroupManagers().abandonInstances(this.group.getProject(),
this.group.getZone(), this.group.getName(), abandonRequest).execute();
} catch (IOException e) {
throw GceErrors.wrap(String.format(
"failed to abandon instances %s from instance group %s in project %s and zone %s: %s", instanceUrls,
this.group.getName(), this.group.getProject(), this.group.getZone(), e.getMessage()), e);
}
}
示例14: resize
import com.google.api.services.compute.model.Operation; //导入依赖的package包/类
@Override
public Operation resize(int targetSize) throws GceException {
try {
return this.apiClient.regionInstanceGroupManagers()
.resize(this.group.getProject(), this.group.getRegion(), this.group.getName(), targetSize)
.execute();
} catch (IOException e) {
throw GceErrors
.wrap(String.format("failed to resize instance group %s in project %s and region %s to size %d: %s",
this.group.getName(), this.group.getProject(), this.group.getRegion(), targetSize,
e.getMessage()), e);
}
}
示例15: deleteInstances
import com.google.api.services.compute.model.Operation; //导入依赖的package包/类
@Override
public Operation deleteInstances(List<String> instanceUrls) {
try {
RegionInstanceGroupManagersDeleteInstancesRequest deleteRequest = new RegionInstanceGroupManagersDeleteInstancesRequest()
.setInstances(instanceUrls);
return this.apiClient.regionInstanceGroupManagers().deleteInstances(this.group.getProject(),
this.group.getRegion(), this.group.getName(), deleteRequest).execute();
} catch (IOException e) {
throw GceErrors.wrap(String.format(
"failed to delete instances %s from instance group %s in project %s and region %s: %s",
instanceUrls, this.group.getName(), this.group.getProject(), this.group.getRegion(),
e.getMessage()), e);
}
}