本文整理汇总了Java中com.google.api.services.compute.model.Operation类的典型用法代码示例。如果您正苦于以下问题:Java Operation类的具体用法?Java Operation怎么用?Java Operation使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Operation类属于com.google.api.services.compute.model包,在下文中一共展示了Operation类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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);
}
}
开发者ID:hortonworks,项目名称:cloudbreak,代码行数:22,代码来源:GcpInstanceResourceBuilder.java
示例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();
}
开发者ID:hortonworks,项目名称:cloudbreak,代码行数:25,代码来源:GcpNetworkResourceBuilder.java
示例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());
}
}
开发者ID:hortonworks,项目名称:cloudbreak,代码行数:23,代码来源:GcpFirewallInResourceBuilder.java
示例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);
}
开发者ID:hortonworks,项目名称:cloudbreak,代码行数:22,代码来源:GcpFirewallInResourceBuilder.java
示例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);
}
}
开发者ID:hortonworks,项目名称:cloudbreak,代码行数:17,代码来源:GcpFirewallInResourceBuilder.java
示例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;
}
开发者ID:hortonworks,项目名称:cloudbreak,代码行数:25,代码来源:AbstractGcpResourceBuilder.java
示例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());
}
}
开发者ID:hortonworks,项目名称:cloudbreak,代码行数:20,代码来源:GcpCreateVirtualNetworkTest.java
示例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();
}
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:8,代码来源:ComputeEngineSample.java
示例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)));
}
开发者ID:elastisys,项目名称:scale.cloudpool,代码行数:11,代码来源:ResizeMultiZoneInstanceGroup.java
示例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);
}
}
开发者ID:elastisys,项目名称:scale.cloudpool,代码行数:14,代码来源:StandardComputeClient.java
示例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);
}
}
开发者ID:elastisys,项目名称:scale.cloudpool,代码行数:12,代码来源:SingleZoneInstanceGroupClient.java
示例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);
}
}
开发者ID:elastisys,项目名称:scale.cloudpool,代码行数:15,代码来源:SingleZoneInstanceGroupClient.java
示例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);
}
}
开发者ID:elastisys,项目名称:scale.cloudpool,代码行数:14,代码来源:SingleZoneInstanceGroupClient.java
示例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);
}
}
开发者ID:elastisys,项目名称:scale.cloudpool,代码行数:14,代码来源:MultiZoneInstanceGroupClient.java
示例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);
}
}
开发者ID:elastisys,项目名称:scale.cloudpool,代码行数:15,代码来源:MultiZoneInstanceGroupClient.java
示例16: abandonInstances
import com.google.api.services.compute.model.Operation; //导入依赖的package包/类
@Override
public Operation abandonInstances(List<String> instanceUrls) throws GceException {
try {
RegionInstanceGroupManagersAbandonInstancesRequest abandonRequest = new RegionInstanceGroupManagersAbandonInstancesRequest()
.setInstances(instanceUrls);
return this.apiClient.regionInstanceGroupManagers().abandonInstances(this.group.getProject(),
this.group.getRegion(), 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 region %s: %s",
instanceUrls, this.group.getName(), this.group.getProject(), this.group.getRegion(),
e.getMessage()), e);
}
}
开发者ID:elastisys,项目名称:scale.cloudpool,代码行数:15,代码来源:MultiZoneInstanceGroupClient.java
示例17: delete
import com.google.api.services.compute.model.Operation; //导入依赖的package包/类
@Override
public CloudResource delete(GcpContext context, AuthenticatedContext auth, CloudResource resource) throws Exception {
String resourceName = resource.getName();
try {
Operation operation = context.getCompute().instances()
.delete(context.getProjectId(), context.getLocation().getAvailabilityZone().value(), resourceName).execute();
return createOperationAwareCloudResource(resource, operation);
} catch (GoogleJsonResponseException e) {
exceptionHandler(e, resourceName, resourceType());
}
return null;
}
开发者ID:hortonworks,项目名称:cloudbreak,代码行数:13,代码来源:GcpInstanceResourceBuilder.java
示例18: checkInstances
import com.google.api.services.compute.model.Operation; //导入依赖的package包/类
@Override
public List<CloudVmInstanceStatus> checkInstances(GcpContext context, AuthenticatedContext auth, List<CloudInstance> instances) {
CloudInstance cloudInstance = instances.get(0);
try {
LOGGER.info("Checking instance: {}", cloudInstance);
Operation operation = check(context, cloudInstance);
boolean finished = operation == null || GcpStackUtil.isOperationFinished(operation);
InstanceStatus status = finished ? context.isBuild() ? InstanceStatus.STARTED : InstanceStatus.STOPPED : InstanceStatus.IN_PROGRESS;
LOGGER.info("Instance: {} status: {}", instances, status);
return Collections.singletonList(new CloudVmInstanceStatus(cloudInstance, status));
} catch (Exception ignored) {
LOGGER.info("Failed to check instance state of {}", cloudInstance);
return Collections.singletonList(new CloudVmInstanceStatus(cloudInstance, InstanceStatus.IN_PROGRESS));
}
}
开发者ID:hortonworks,项目名称:cloudbreak,代码行数:16,代码来源:GcpInstanceResourceBuilder.java
示例19: 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());
}
}
开发者ID:hortonworks,项目名称:cloudbreak,代码行数:29,代码来源:GcpDiskResourceBuilder.java
示例20: delete
import com.google.api.services.compute.model.Operation; //导入依赖的package包/类
@Override
public CloudResource delete(GcpContext context, AuthenticatedContext auth, CloudResource resource) throws Exception {
String resourceName = resource.getName();
try {
Operation operation = context.getCompute().disks()
.delete(context.getProjectId(), context.getLocation().getAvailabilityZone().value(), resourceName).execute();
return createOperationAwareCloudResource(resource, operation);
} catch (GoogleJsonResponseException e) {
exceptionHandler(e, resourceName, resourceType());
}
return null;
}
开发者ID:hortonworks,项目名称:cloudbreak,代码行数:13,代码来源:GcpDiskResourceBuilder.java
注:本文中的com.google.api.services.compute.model.Operation类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论