@Override public Operation create(InstanceInfo instance, OperationOption... options) { final InstanceInfo completeInstance = instance.setProjectId(getOptions().getProjectId()); final Map<ComputeRpc.Option, ?> optionsMap = optionMap(options); try { com.google.api.services.compute.model.Operation answer = runWithRetries( new Callable<com.google.api.services.compute.model.Operation>() { @Override public com.google.api.services.compute.model.Operation call() { return computeRpc.createInstance( completeInstance.getInstanceId().getZone(), completeInstance.toPb(), optionsMap); } }, getOptions().getRetrySettings(), EXCEPTION_HANDLER, getOptions().getClock()); return answer == null ? null : Operation.fromPb(this, answer); } catch (RetryHelper.RetryHelperException e) { throw ComputeException.translateAndThrow(e); } }
@Test public void testSetProjectId() { InstanceInfo instance = InstanceInfo.of( InstanceId.of("zone", "instance"), MachineTypeId.of("zone", "type"), AttachedDisk.of(AttachedDisk.PersistentDiskConfiguration.of(DiskId.of("zone", "disk"))), NetworkInterface.of(NetworkId.of("project", "network"))); InstanceInfo instanceWithProject = InstanceInfo.of(INSTANCE_ID, MACHINE_TYPE, ATTACHED_DISK, NETWORK_INTERFACE); compareInstanceInfo(instanceWithProject, instance.setProjectId("project")); }