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


Java Items类代码示例

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


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

示例1: setTags

import com.google.api.services.compute.model.Metadata.Items; //导入依赖的package包/类
@Override
public void setTags(Iterable<String> instanceIds, Tags tags)
{
    Instances instances = this.listInstances(instanceIds);
    Metadata metadata = new Metadata().setItems(new ArrayList<Metadata.Items>());
    
    for (Tag tag: tags)
    {
        metadata.getItems().add(new Items().setKey(tag.getName()).setValue(tag.getValue()));
    }
    
    for (VirtualMachine instance : instances)
    {
        this.compute.instances().setMetadata(this.credentials_.getProject(), instance.getLocation().getName(), instance.getName(), metadata);
    }
}
 
开发者ID:alessandroleite,项目名称:dohko,代码行数:17,代码来源:GoogleCompute.java

示例2: toItems

import com.google.api.services.compute.model.Metadata.Items; //导入依赖的package包/类
/**
 * Verify conversion of a {@link Map} to a list of {@link Items}.
 */
@Test
public void toItems() {
    Map<String, String> map = ImmutableMap.of(//
            "startup-script", "#!/bin/bash\napt update -qy && apt install -qy apache2", //
            "ssh-keys", "foo:ssh-rsa XXXXXXXX [email protected]");

    // convert
    List<Items> items = MetadataUtil.toItems(map);

    // verify
    assertThat(items,
            is(items(//
                    item("startup-script", "#!/bin/bash\napt update -qy && apt install -qy apache2"), //
                    item("ssh-keys", "foo:ssh-rsa XXXXXXXX [email protected]"))));
}
 
开发者ID:elastisys,项目名称:scale.cloudpool,代码行数:19,代码来源:TestMetadataUtil.java

示例3: apply

import com.google.api.services.compute.model.Metadata.Items; //导入依赖的package包/类
@Override
@Nullable
public Map<String, String> apply(@Nullable List<Items> items)
{
    Map<String, String> values = new HashMap<String, String>();
    
    for (Items item: items)
    {
        if (item != null)
        {
            values.put(item.getKey(), item.getValue());
        }
    }
    return Collections.unmodifiableMap(values);
}
 
开发者ID:alessandroleite,项目名称:dohko,代码行数:16,代码来源:GoogleCompute.java

示例4: toMap

import com.google.api.services.compute.model.Metadata.Items; //导入依赖的package包/类
/**
 * Converts the {@link Items} in an instance's {@link Metadata} to a
 * {@link Map}.
 *
 * @param metadata
 * @return
 */
public static Map<String, String> toMap(Metadata metadata) {
    if (metadata == null) {
        return Collections.emptyMap();
    }

    Map<String, String> map = new HashMap<>();
    for (Items item : metadata.getItems()) {
        map.put(item.getKey(), item.getValue());
    }
    return map;
}
 
开发者ID:elastisys,项目名称:scale.cloudpool,代码行数:19,代码来源:MetadataUtil.java

示例5: toItems

import com.google.api.services.compute.model.Metadata.Items; //导入依赖的package包/类
/**
 * Takes a {@link Map} of key-value pairs and produces a corresponding list
 * of instance {@link Metadata} {@link Items}.
 *
 * @param map
 * @return
 */
public static List<Items> toItems(Map<String, String> map) {
    if (map == null) {
        return Collections.emptyList();
    }

    List<Items> items = new ArrayList<>();
    for (Entry<String, String> keyValuePair : map.entrySet()) {
        items.add(new Items().setKey(keyValuePair.getKey()).setValue(keyValuePair.getValue()));
    }
    return items;
}
 
开发者ID:elastisys,项目名称:scale.cloudpool,代码行数:19,代码来源:MetadataUtil.java

示例6: toItemsOnEmptyMap

import com.google.api.services.compute.model.Metadata.Items; //导入依赖的package包/类
@Test
public void toItemsOnEmptyMap() {
    Map<String, String> map = new HashMap<>();

    // convert
    List<Items> items = MetadataUtil.toItems(map);

    // verify
    assertThat(items, is(items()));
}
 
开发者ID:elastisys,项目名称:scale.cloudpool,代码行数:11,代码来源:TestMetadataUtil.java

示例7: toItemsOnNullMap

import com.google.api.services.compute.model.Metadata.Items; //导入依赖的package包/类
@Test
public void toItemsOnNullMap() {
    // convert
    List<Items> items = MetadataUtil.toItems(null);

    // verify
    assertThat(items, is(items()));
}
 
开发者ID:elastisys,项目名称:scale.cloudpool,代码行数:9,代码来源:TestMetadataUtil.java

示例8: createInstanceFromTemplate

import com.google.api.services.compute.model.Metadata.Items; //导入依赖的package包/类
protected Instance createInstanceFromTemplate(InstanceTemplate template)
{
    Instance instance = new Instance()
            .setMachineType(template.getInstanceType().getName())
            .setName(template.getInstanceName())
            .setNetworkInterfaces(new ArrayList<NetworkInterface>());
    
    instance.getNetworkInterfaces().add(new NetworkInterface().setAccessConfigs(new ArrayList<AccessConfig>()).setNetwork(
            String.format("https://www.googleapis.com/compute/v1/projects/%s/global/networks/default", credentials_.getProject())));
    instance.getNetworkInterfaces().get(0).getAccessConfigs().add(new AccessConfig().setName("External NAT").setType("ONE_TO_ONE_NAT"));

    instance.setZone(template.getRegion().getName());
    instance.setMachineType(getMachineType(instance.getZone(), template.getInstanceType().getName()).getSelfLink());

    instance.setDisks(new ArrayList<AttachedDisk>());
    instance.getDisks().add(new AttachedDisk()
            .setType("PERSISTENT")
            .setAutoDelete(false)
            .setBoot(true)
            .setMode("READ_WRITE")
            .setInitializeParams(
                    new AttachedDiskInitializeParams()
                            .setDiskName(template.getInstanceName())
                            .setDiskSizeGb(SystemUtils2.getIntegerProperty("org.excalibur.default.disk.size", 10).longValue())
                            .setSourceImage(VM_IMAGES_NAME_MAPPING.get(template.getImageId()))));

    List<Items> items = new ArrayList<Metadata.Items>();
    
    Metadata metadata = new Metadata().setItems(items);
    instance.setMetadata(metadata);
    
    items.add
    (       new Items().setKey("sshKeys")
                       .setValue(String.format("%s:%s", template.getLoginCredentials().getUser(), 
                               decrypt(template.getLoginCredentials().getPublicKey()).replaceAll("\n", "")))
    );
    
    items.add(new Items().setKey("image-id").setValue(template.getImageId()));
    items.add(new Items().setKey("keyname").setValue(template.getKeyName().toLowerCase()));
    items.add(new Items().setKey("zone").setValue(instance.getZone()));
    items.add(new Items().setKey("platform").setValue(Platform.LINUX.name().toLowerCase()));
    items.add(new Items().setKey("platform-username").setValue(template.getLoginCredentials().getUser()));
    items.add(new Items().setKey("owner").setValue(template.getLoginCredentials().getUser()));
    items.add(new Items().setKey("pem-key").setValue(Base64.encodeBase64URLSafeString(template.getLoginCredentials().getPrivateKey().getBytes())));
    
    
    for (Tag tag: template.getTags())
    {
        items.add(new Items().setKey(tag.getName()).setValue(tag.getValue()));
    }
    
    return instance;
}
 
开发者ID:alessandroleite,项目名称:dohko,代码行数:54,代码来源:GoogleCompute.java

示例9: item

import com.google.api.services.compute.model.Metadata.Items; //导入依赖的package包/类
private Items item(String key, String value) {
    return new Items().setKey(key).setValue(value);
}
 
开发者ID:elastisys,项目名称:scale.cloudpool,代码行数:4,代码来源:TestMetadataUtil.java


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