BuilderImpl(Instance instancePb) { if (instancePb.getId() != null) { this.generatedId = instancePb.getId().toString(); this.instanceId = InstanceId.fromUrl(instancePb.getSelfLink()); if (instancePb.getCreationTimestamp() != null) { this.creationTimestamp = TIMESTAMP_FORMATTER.parseMillis(instancePb.getCreationTimestamp()); this.description = instancePb.getDescription(); if (instancePb.getStatus() != null) { this.status = Status.valueOf(instancePb.getStatus()); this.statusMessage = instancePb.getStatusMessage(); if (instancePb.getTags() != null) { this.tags = Tags.fromPb(instancePb.getTags()); if (instancePb.getMachineType() != null) { this.machineType = MachineTypeId.fromUrl(instancePb.getMachineType()); this.canIpForward = instancePb.getCanIpForward(); if (instancePb.getNetworkInterfaces() != null) { this.networkInterfaces = Lists.transform(instancePb.getNetworkInterfaces(), NetworkInterface.FROM_PB_FUNCTION); if (instancePb.getDisks() != null) { this.attachedDisks = Lists.transform(instancePb.getDisks(), AttachedDisk.FROM_PB_FUNCTION); if (instancePb.getMetadata() != null) { this.metadata = Metadata.fromPb(instancePb.getMetadata());
Instance toPb() { Instance instancePb = new Instance(); if (generatedId != null) { instancePb.setId(new BigInteger(generatedId)); instancePb.setCreationTimestamp(TIMESTAMP_FORMATTER.print(creationTimestamp)); instancePb.setName(instanceId.getInstance()); instancePb.setDescription(description); instancePb.setSelfLink(instanceId.getSelfLink()); instancePb.setZone(instanceId.getZoneId().getSelfLink()); if (status != null) { instancePb.setStatus(status.name()); instancePb.setStatusMessage(statusMessage); if (tags != null) { instancePb.setTags(tags.toPb()); instancePb.setMachineType(machineType.getSelfLink()); instancePb.setCanIpForward(canIpForward); if (networkInterfaces != null) { instancePb.setNetworkInterfaces( Lists.transform(networkInterfaces, NetworkInterface.TO_PB_FUNCTION)); instancePb.setDisks(Lists.transform(attachedDisks, AttachedDisk.TO_PB_FUNCTION)); instancePb.setMetadata(metadata.toPb()); instancePb.setServiceAccounts(
Instance instance = new Instance(); instance.setName(instanceName); instance.setMachineType( "https://www.googleapis.com/compute/v1/projects/" + PROJECT_ID + "/zones/" + ZONE_NAME + "/machineTypes/n1-standard-1"); configs.add(config); ifc.setAccessConfigs(configs); instance.setNetworkInterfaces(Collections.singletonList(ifc)); + ZONE_NAME + "/diskTypes/pd-standard"); disk.setInitializeParams(params); instance.setDisks(Collections.singletonList(disk)); scopes.add("https://www.googleapis.com/auth/compute"); account.setScopes(scopes); instance.setServiceAccounts(Collections.singletonList(account)); instance.setMetadata(meta); System.out.println(instance.toPrettyString()); Compute.Instances.Insert insert = compute.instances().insert(PROJECT_ID, ZONE_NAME, instance); return insert.execute();
Instance instance = new Instance(); instance .setName(instanceName) .setZone(String.format("projects/%s/zones/%s", provider.project, provider.zone)) .setMachineType(String.format("projects/%s/zones/%s/machineTypes/%s", provider.project, provider.zone, provider.machineType)) .setMetadata( new Metadata() .setItems(new ImmutableList.Builder<Metadata.Items>() .setValue(startupScript)) .build())) .setDisks(new ImmutableList.Builder<AttachedDisk>() .add(new AttachedDisk() .setType("PERSISTENT") provider.project, provider.zone, instanceName))) .build()) .setCanIpForward(false) .setNetworkInterfaces(new ImmutableList.Builder<NetworkInterface>() .add(new NetworkInterface() .setNetwork(String.format("projects/%s/global/networks/default", .build())) .build()) .setServiceAccounts(new ImmutableList.Builder<ServiceAccount>().add( new ServiceAccount() .setEmail("default")
builder.id(instance.getSelfLink()); builder.region(ZoneUtils.regionName(ZoneUtils.zoneName(instance.getZone()))); builder.machineSize(UrlUtils.basename(instance.getMachineType())); builder.machineState(new InstanceStatusToMachineStatus().apply(instance.getStatus())); builder.launchTime(UtcTime.parse(instance.getCreationTimestamp())); List<NetworkInterface> networkInterfaces = instance.getNetworkInterfaces(); if (networkInterfaces != null && !networkInterfaces.isEmpty()) { NetworkInterface networkInterface = networkInterfaces.get(0);
static String getInstanceIp(AccountDeploymentDetails<GoogleAccount> details, String instanceName) { Compute compute = getCompute(details); Instance instance = null; try { instance = compute.instances().get(details.getAccount().getProject(), "us-central1-f", instanceName).execute(); } catch (IOException e) { throw new HalException(FATAL, "Unable to get instance " + instanceName); } return instance.getNetworkInterfaces() .stream() .map(i -> i.getAccessConfigs().stream() .map(AccessConfig::getNatIP) .filter(ip -> !StringUtils.isEmpty(ip)) .findFirst() ).filter(Optional::isPresent) .map(Optional::get) .findFirst() .orElseThrow(() -> new HalException(FATAL, "No public IP associated with" + instanceName)); }
for (NetworkInterface networkInterface : instance.getNetworkInterfaces()) { Path path = Paths.get(networkInterface.getNetwork()); String networkName = path.getFileName().toString(); ts = DATE_FORMAT.parse(instance.getCreationTimestamp()).getTime(); } catch (ParseException e) { ts = -1L;
static String getInstanceIp(AccountDeploymentDetails<GoogleAccount> details, String instanceName) { Compute compute = getCompute(details); Instance instance = null; try { instance = compute.instances().get(details.getAccount().getProject(), "us-central1-f", instanceName).execute(); } catch (IOException e) { throw new HalException(FATAL, "Unable to get instance " + instanceName); } return instance.getNetworkInterfaces() .stream() .map(i -> i.getAccessConfigs().stream() .map(AccessConfig::getNatIP) .filter(ip -> !StringUtils.isEmpty(ip)) .findFirst() ).filter(Optional::isPresent) .map(Optional::get) .findFirst() .orElseThrow(() -> new HalException(FATAL, "No public IP associated with" + instanceName)); }
Instance toPb() { Instance instancePb = new Instance(); if (generatedId != null) { instancePb.setId(new BigInteger(generatedId)); instancePb.setCreationTimestamp(TIMESTAMP_FORMATTER.print(creationTimestamp)); instancePb.setName(instanceId.getInstance()); instancePb.setDescription(description); instancePb.setSelfLink(instanceId.getSelfLink()); instancePb.setZone(instanceId.getZoneId().getSelfLink()); if (status != null) { instancePb.setStatus(status.name()); instancePb.setStatusMessage(statusMessage); if (tags != null) { instancePb.setTags(tags.toPb()); instancePb.setMachineType(machineType.getSelfLink()); instancePb.setCanIpForward(canIpForward); if (networkInterfaces != null) { instancePb.setNetworkInterfaces( Lists.transform(networkInterfaces, NetworkInterface.TO_PB_FUNCTION)); instancePb.setDisks(Lists.transform(attachedDisks, AttachedDisk.TO_PB_FUNCTION)); instancePb.setMetadata(metadata.toPb()); instancePb.setServiceAccounts(
BuilderImpl(Instance instancePb) { if (instancePb.getId() != null) { this.generatedId = instancePb.getId().toString(); this.instanceId = InstanceId.fromUrl(instancePb.getSelfLink()); if (instancePb.getCreationTimestamp() != null) { this.creationTimestamp = TIMESTAMP_FORMATTER.parseMillis(instancePb.getCreationTimestamp()); this.description = instancePb.getDescription(); if (instancePb.getStatus() != null) { this.status = Status.valueOf(instancePb.getStatus()); this.statusMessage = instancePb.getStatusMessage(); if (instancePb.getTags() != null) { this.tags = Tags.fromPb(instancePb.getTags()); if (instancePb.getMachineType() != null) { this.machineType = MachineTypeId.fromUrl(instancePb.getMachineType()); this.canIpForward = instancePb.getCanIpForward(); if (instancePb.getNetworkInterfaces() != null) { this.networkInterfaces = Lists.transform(instancePb.getNetworkInterfaces(), NetworkInterface.FROM_PB_FUNCTION); if (instancePb.getDisks() != null) { this.attachedDisks = Lists.transform(instancePb.getDisks(), AttachedDisk.FROM_PB_FUNCTION); if (instancePb.getMetadata() != null) { this.metadata = Metadata.fromPb(instancePb.getMetadata());
/** * For the given zone and client type, we add the instances created to the clients array, for the * base controller. */ private void addInstanceGroupInfo(String zone, ClientParams params) throws IOException { InstanceGroupManagersListManagedInstancesResponse response; do { response = compute.instanceGroupManagers(). listManagedInstances(projectName, zone, "cps-loadtest-" + params.getClientType() + "-" + cores).execute(); // If we are not instantiating any instances of this type, just return. if (response.getManagedInstances() == null) { return; } } while (!response.getManagedInstances().stream() .allMatch(i -> i.getCurrentAction().equals("NONE"))); for (ManagedInstance managedInstance : response.getManagedInstances()) { String instanceName = managedInstance.getInstance() .substring(managedInstance.getInstance().lastIndexOf('/') + 1); Instance instance = compute.instances().get(projectName, zone, instanceName).execute(); synchronized (this) { clients.add(new Client( params.getClientType(), instance.getNetworkInterfaces().get(0).getAccessConfigs().get(0).getNatIP(), projectName, params.subscription, executor)); } } }