当前位置: 首页>>代码示例>>Java>>正文


Java InstanceTemplate类代码示例

本文整理汇总了Java中com.google.api.services.compute.model.InstanceTemplate的典型用法代码示例。如果您正苦于以下问题:Java InstanceTemplate类的具体用法?Java InstanceTemplate怎么用?Java InstanceTemplate使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


InstanceTemplate类属于com.google.api.services.compute.model包,在下文中一共展示了InstanceTemplate类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: startMachines

import com.google.api.services.compute.model.InstanceTemplate; //导入依赖的package包/类
@Override
public List<Machine> startMachines(int count) throws IllegalStateException, StartMachinesException {
    ensureConfigured();

    if (count == 0) {
        return Collections.emptyList();
    }

    InstanceGroupClient instanceGroupApi = instanceGroupClient();
    InstanceGroupManager instanceGroup = instanceGroupApi.getInstanceGroup();
    int targetSize = instanceGroup.getTargetSize() + count;
    LOG.info("starting {} new instances in instance group '{}': changing targetSize from {} to {}", count,
            instanceGroup.getName(), instanceGroup.getTargetSize(), targetSize);
    instanceGroupApi.resize(targetSize);

    InstanceTemplate instanceTemplate = this.client.getInstanceTemplate(instanceGroup.getInstanceTemplate());

    return placeholderMachines(count, instanceTemplate);
}
 
开发者ID:elastisys,项目名称:scale.cloudpool,代码行数:20,代码来源:GoogleComputeEnginePoolDriver.java

示例2: defaultInstanceTemplate

import com.google.api.services.compute.model.InstanceTemplate; //导入依赖的package包/类
/**
 * Creates the default instance template for each type. Each type only changes the name and
 * startup script used.
 */
private InstanceTemplate defaultInstanceTemplate(String type) {
  AccessConfig config = new AccessConfig();
  config.setType("ONE_TO_ONE_NAT");
  config.setName("External NAT");
  return new InstanceTemplate()
      .setName("cps-loadtest-" + type + "-" + cores)
      .setProperties(new InstanceProperties()
          .setMachineType(MACHINE_TYPE + cores)
          .setDisks(Collections.singletonList(new AttachedDisk()
              .setBoot(true)
              .setAutoDelete(true)
              .setInitializeParams(new AttachedDiskInitializeParams()
                  .setSourceImage(SOURCE_FAMILY))))
          .setNetworkInterfaces(Collections.singletonList(new NetworkInterface()
              .setNetwork("global/networks/default")
              .setAccessConfigs(Collections.singletonList(config))))
          .setMetadata(new Metadata()
              .setItems(ImmutableList.of(
                  new Metadata.Items()
                      .setKey("startup-script-url")
                      .setValue("https://storage.googleapis.com/"
                          + projectName
                          + "-cloud-pubsub-loadtest/"
                          + type
                          + "_startup_script.sh"),
                  new Metadata.Items()
                      .setKey("bucket")
                      .setValue(projectName + "-cloud-pubsub-loadtest"))))
          .setServiceAccounts(Collections.singletonList(new ServiceAccount().setScopes(
              Collections.singletonList("https://www.googleapis.com/auth/cloud-platform")))));
}
 
开发者ID:GoogleCloudPlatform,项目名称:pubsub,代码行数:36,代码来源:GCEController.java

示例3: listMachines

import com.google.api.services.compute.model.InstanceTemplate; //导入依赖的package包/类
@Override
public List<Machine> listMachines() throws IllegalStateException, CloudPoolDriverException {
    ensureConfigured();

    InstanceGroupClient instanceGroupApi = instanceGroupClient();
    InstanceGroupManager instanceGroup = instanceGroupApi.getInstanceGroup();
    List<ManagedInstance> members = instanceGroupApi.listInstances();

    // fetch detailed metadata about each member instance
    List<Instance> instances = new ArrayList<>();
    for (ManagedInstance member : members) {
        String instanceUrl = member.getInstance();
        Instance instance = this.client.getInstance(instanceUrl);
        instances.add(instance);
    }

    // convert from Instance to Machine
    List<Machine> machines = instances.stream().map(new InstanceToMachine()::apply).collect(Collectors.toList());

    int numMembers = members.size();
    // use max of targetSize and number of member instances since there is a
    // small chance that the group size has changed between the call to get
    // the instance group metadata and the call to list instances
    int targetSize = Math.max(instanceGroup.getTargetSize(), numMembers);
    int numAwaiting = targetSize - numMembers;
    LOG.debug("psuedo (requested) instances: {}   (member instances: {}, target size: {})", numAwaiting, numMembers,
            instanceGroup.getTargetSize());
    if (numAwaiting > 0) {
        // return placeholder machines for requested-but-not-yet-acquired
        InstanceTemplate instanceTemplate = this.client.getInstanceTemplate(instanceGroup.getInstanceTemplate());
        machines.addAll(placeholderMachines(numAwaiting, instanceTemplate));
    }

    return machines;
}
 
开发者ID:elastisys,项目名称:scale.cloudpool,代码行数:36,代码来源:GoogleComputeEnginePoolDriver.java

示例4: placeholderMachines

import com.google.api.services.compute.model.InstanceTemplate; //导入依赖的package包/类
/**
 * Creates a number of placeholder {@link Machine}s in {@code REQUESTED}
 * machine state to represent instances that have been requested but not yet
 * been acquired by the backing GCE instance group.
 *
 * @param numPseudoMachines
 * @param instanceTemplate
 * @return
 */
private List<Machine> placeholderMachines(int numPseudoMachines, InstanceTemplate instanceTemplate) {
    List<Machine> psuedoMachines = new ArrayList<>();
    for (int i = 1; i <= numPseudoMachines; i++) {
        psuedoMachines
                .add(Machine.builder().id(REQUESTED_INSTANCE_PREFIX + "-" + instanceTemplate.getName() + "-" + i)
                        .cloudProvider(CloudProviders.GCE).region(getRegion())
                        .machineSize(instanceTemplate.getProperties().getMachineType())
                        .machineState(MachineState.REQUESTED).launchTime(UtcTime.now()).build());
    }
    return psuedoMachines;
}
 
开发者ID:elastisys,项目名称:scale.cloudpool,代码行数:21,代码来源:GoogleComputeEnginePoolDriver.java

示例5: main

import com.google.api.services.compute.model.InstanceTemplate; //导入依赖的package包/类
public static void main(String[] args) throws GeneralSecurityException, IOException {
    Compute api = computeApiClient();

    Get request = api.regionInstanceGroupManagers().get(project, region, instanceGroup);
    InstanceGroupManager instanceGroupManager = request.execute();
    LOG.debug("multi-zone instance group: {}", instanceGroupManager.toPrettyString());

    String instanceTemplateUrl = instanceGroupManager.getInstanceTemplate();
    InstanceTemplate instanceTemplate = api.instanceTemplates().get(project, UrlUtils.basename(instanceTemplateUrl))
            .execute();
    LOG.debug("instance template: {}", instanceTemplate.toPrettyString());

    RegionInstanceGroupManagersListInstancesResponse listManagedInstances = api.regionInstanceGroupManagers()
            .listManagedInstances(project, region, instanceGroup).execute();
    List<ManagedInstance> groupInstances = listManagedInstances.getManagedInstances();
    if (groupInstances != null) {
        for (ManagedInstance member : groupInstances) {
            LOG.debug("member: {}", member);

            InstanceUrl instanceUrl = new InstanceUrl(member.getInstance());
            LOG.debug("instance URL: {}", instanceUrl);

            Instance instance = api.instances().get(project, instanceUrl.getZone(), instanceUrl.getName())
                    .execute();
            LOG.debug("instance: {}", instance.toPrettyString());
        }
    }
}
 
开发者ID:elastisys,项目名称:scale.cloudpool,代码行数:29,代码来源:GetMultiZoneInstanceGroup.java

示例6: main

import com.google.api.services.compute.model.InstanceTemplate; //导入依赖的package包/类
public static void main(String[] args) throws GeneralSecurityException, IOException {
    Compute api = computeApiClient();

    Get request = api.instanceGroupManagers().get(project, zone, instanceGroup);
    InstanceGroupManager instanceGroupManager = request.execute();
    LOG.debug("single-zone instance group: {}", instanceGroupManager.toPrettyString());

    String instanceTemplateUrl = instanceGroupManager.getInstanceTemplate();
    InstanceTemplate instanceTemplate = api.instanceTemplates().get(project, UrlUtils.basename(instanceTemplateUrl))
            .execute();
    LOG.debug("instance template: {}", instanceTemplate.toPrettyString());

    InstanceGroupManagersListManagedInstancesResponse listManagedInstances = api.instanceGroupManagers()
            .listManagedInstances(project, zone, instanceGroup).execute();
    List<ManagedInstance> groupInstances = listManagedInstances.getManagedInstances();
    if (groupInstances != null) {
        for (ManagedInstance member : groupInstances) {
            LOG.debug("member: {}", member);

            InstanceUrl instanceUrl = new InstanceUrl(member.getInstance());
            LOG.debug("instance URL: {}", instanceUrl);

            Instance instance = api.instances().get(project, instanceUrl.getZone(), instanceUrl.getName())
                    .execute();
            LOG.debug("instance: {}", instance.toPrettyString());
        }
    }
}
 
开发者ID:elastisys,项目名称:scale.cloudpool,代码行数:29,代码来源:GetSingleZoneInstanceGroup.java

示例7: getInstanceTemplate

import com.google.api.services.compute.model.InstanceTemplate; //导入依赖的package包/类
@Override
public InstanceTemplate getInstanceTemplate(String instanceTemplateUrl) throws NotFoundException, GceException {
    ensureConfigured();

    InstanceTemplateUrl template = new InstanceTemplateUrl(instanceTemplateUrl);
    try {
        return this.apiClient.instanceTemplates().get(template.getProject(), template.getName()).execute();
    } catch (IOException e) {
        throw GceErrors.wrap(String.format("unable to get instance template %s in project %s: %s",
                template.getName(), template.getProject(), e.getMessage()), e);
    }
}
 
开发者ID:elastisys,项目名称:scale.cloudpool,代码行数:13,代码来源:StandardComputeClient.java

示例8: instanceTemplate

import com.google.api.services.compute.model.InstanceTemplate; //导入依赖的package包/类
/**
 * Returns the (fake) {@link InstanceTemplate} from which the group members
 * are created.
 * <p/>
 * Note: only a subset of the template attributes are set (the ones needed
 * by the {@link GoogleComputeEnginePoolDriver}.
 *
 * @return
 */
public InstanceTemplate instanceTemplate() {
    return new InstanceTemplate().setName(INSTANCE_TEMPLATE_NAME)
            .setProperties(new InstanceProperties().setMachineType(MACHINE_TYPE_NAME));
}
 
开发者ID:elastisys,项目名称:scale.cloudpool,代码行数:14,代码来源:FakeMultiZoneInstanceGroup.java

示例9: getInstanceTemplate

import com.google.api.services.compute.model.InstanceTemplate; //导入依赖的package包/类
/**
 * Returns an instance template.
 *
 * @param instanceTemplateUrl
 *            The instance template URL. For example,
 *            {@code https://www.googleapis.com/compute/v1/projects/my-project/global/instanceTemplates/webserver-template}.
 * @return
 * @throws NotFoundException
 *             If the instance template could not be found.
 * @throws CloudPoolDriverException
 */
InstanceTemplate getInstanceTemplate(String instanceTemplateUrl) throws NotFoundException, CloudPoolDriverException;
 
开发者ID:elastisys,项目名称:scale.cloudpool,代码行数:13,代码来源:ComputeClient.java


注:本文中的com.google.api.services.compute.model.InstanceTemplate类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。