public Set<IPForwardingRule> apply(PublicIPAddress ip, String protocol, Iterable<Integer> ports) { checkState(ip.getVirtualMachineId() != null, "ip %s should be static NATed to a virtual machine before applying rules", ip); if (Iterables.size(ports) == 0) return ImmutableSet.<IPForwardingRule> of(); Builder<AsyncCreateResponse> responses = ImmutableSet.builder(); for (int port : ports) { AsyncCreateResponse response = client.getNATClient().createIPForwardingRule(ip.getId(), protocol, port); logger.debug(">> creating IP forwarding rule IPAddress(%s) for protocol(%s), port(%s); response(%s)", ip.getId(), protocol, port, response); responses.add(response); } Builder<IPForwardingRule> rules = ImmutableSet.builder(); for (AsyncCreateResponse response : responses.build()) { IPForwardingRule rule = blockUntilJobCompletesAndReturnResult.<IPForwardingRule> apply(response); rules.add(rule); getIPForwardingRulesByVirtualMachine.asMap().put(ip.getVirtualMachineId(), ImmutableSet.of(rule)); } return rules.build(); } }
public Set<IPForwardingRule> apply(PublicIPAddress ip, String protocol, Iterable<Integer> ports) { checkState(ip.getVirtualMachineId() != null, "ip %s should be static NATed to a virtual machine before applying rules", ip); if (Iterables.size(ports) == 0) return ImmutableSet.<IPForwardingRule> of(); Builder<AsyncCreateResponse> responses = ImmutableSet.builder(); for (int port : ports) { AsyncCreateResponse response = client.getNATClient().createIPForwardingRule(ip.getId(), protocol, port); logger.debug(">> creating IP forwarding rule IPAddress(%s) for protocol(%s), port(%s); response(%s)", ip.getId(), protocol, port, response); responses.add(response); } Builder<IPForwardingRule> rules = ImmutableSet.builder(); for (AsyncCreateResponse response : responses.build()) { IPForwardingRule rule = blockUntilJobCompletesAndReturnResult.<IPForwardingRule> apply(response); rules.add(rule); getIPForwardingRulesByVirtualMachine.asMap().put(ip.getVirtualMachineId(), ImmutableSet.of(rule)); } return rules.build(); } }
public Set<IPForwardingRule> apply(PublicIPAddress ip, String protocol, Iterable<Integer> ports) { checkState(ip.getVirtualMachineId() != null, "ip %s should be static NATed to a virtual machine before applying rules", ip); if (Iterables.isEmpty(ports)) return ImmutableSet.<IPForwardingRule> of(); Builder<AsyncCreateResponse> responses = ImmutableSet.builder(); for (int port : ports) { AsyncCreateResponse response = client.getNATApi().createIPForwardingRule(ip.getId(), protocol, port); logger.debug(">> creating IP forwarding rule IPAddress(%s) for protocol(%s), port(%s); response(%s)", ip.getId(), protocol, port, response); responses.add(response); } Builder<IPForwardingRule> rules = ImmutableSet.builder(); for (AsyncCreateResponse response : responses.build()) { IPForwardingRule rule = blockUntilJobCompletesAndReturnResult.<IPForwardingRule> apply(response); rules.add(rule); getIPForwardingRulesByVirtualMachine.asMap().put(ip.getVirtualMachineId(), ImmutableSet.of(rule)); } return rules.build(); } }
public Set<FirewallRule> apply(PublicIPAddress ip, String protocol, Iterable<Integer> ports) { checkState(ip.getVirtualMachineId() != null, "ip %s should be static NATed to a virtual machine before applying rules", ip); if (Iterables.size(ports) == 0) return ImmutableSet.<FirewallRule> of(); Builder<AsyncCreateResponse> responses = ImmutableSet.builder(); for (int port : ports) { AsyncCreateResponse response = client.getFirewallClient().createFirewallRuleForIpAndProtocol(ip.getId(), FirewallRule.Protocol.fromValue(protocol), CreateFirewallRuleOptions.Builder.startPort(port).endPort(port)); logger.debug(">> creating firewall rule IPAddress(%s) for protocol(%s), port(%s); response(%s)", ip.getId(), protocol, port, response); responses.add(response); } Builder<FirewallRule> rules = ImmutableSet.builder(); for (AsyncCreateResponse response : responses.build()) { FirewallRule rule = blockUntilJobCompletesAndReturnResult.<FirewallRule> apply(response); rules.add(rule); getFirewallRulesByVirtualMachine.asMap().put(ip.getVirtualMachineId(), ImmutableSet.of(rule)); } return rules.build(); } }
public Set<FirewallRule> apply(PublicIPAddress ip, String protocol, Iterable<Integer> ports) { checkState(ip.getVirtualMachineId() != null, "ip %s should be static NATed to a virtual machine before applying rules", ip); if (Iterables.size(ports) == 0) return ImmutableSet.<FirewallRule> of(); Builder<AsyncCreateResponse> responses = ImmutableSet.builder(); for (int port : ports) { AsyncCreateResponse response = client.getFirewallClient().createFirewallRuleForIpAndProtocol(ip.getId(), FirewallRule.Protocol.fromValue(protocol), CreateFirewallRuleOptions.Builder.startPort(port).endPort(port)); logger.debug(">> creating firewall rule IPAddress(%s) for protocol(%s), port(%s); response(%s)", ip.getId(), protocol, port, response); responses.add(response); } Builder<FirewallRule> rules = ImmutableSet.builder(); for (AsyncCreateResponse response : responses.build()) { FirewallRule rule = blockUntilJobCompletesAndReturnResult.<FirewallRule> apply(response); rules.add(rule); getFirewallRulesByVirtualMachine.asMap().put(ip.getVirtualMachineId(), ImmutableSet.of(rule)); } return rules.build(); } }
public Set<FirewallRule> apply(PublicIPAddress ip, String protocol, Iterable<Integer> ports) { checkState(ip.getVirtualMachineId() != null, "ip %s should be static NATed to a virtual machine before applying rules", ip); if (Iterables.isEmpty(ports)) return ImmutableSet.<FirewallRule> of(); Builder<AsyncCreateResponse> responses = ImmutableSet.builder(); for (int port : ports) { AsyncCreateResponse response = client.getFirewallApi().createFirewallRuleForIpAndProtocol(ip.getId(), FirewallRule.Protocol.fromValue(protocol), CreateFirewallRuleOptions.Builder.startPort(port).endPort(port)); logger.debug(">> creating firewall rule IPAddress(%s) for protocol(%s), port(%s); response(%s)", ip.getId(), protocol, port, response); responses.add(response); } Builder<FirewallRule> rules = ImmutableSet.builder(); for (AsyncCreateResponse response : responses.build()) { FirewallRule rule = blockUntilJobCompletesAndReturnResult.<FirewallRule> apply(response); rules.add(rule); getFirewallRulesByVirtualMachine.asMap().put(ip.getVirtualMachineId(), ImmutableSet.of(rule)); } return rules.build(); } }
public static PublicIPAddress associateIPAddressInNetwork(Network network, CloudStackClient client, BlockUntilJobCompletesAndReturnResult blockUntilJobCompletesAndReturnResult) { AsyncCreateResponse job = client.getAddressClient().associateIPAddressInZone(network.getZoneId(), networkId(network.getId())); PublicIPAddress ip = blockUntilJobCompletesAndReturnResult.<PublicIPAddress> apply(job); assert ip.getZoneId().equals(network.getZoneId()); return ip; }
public static PublicIPAddress associateIPAddressInNetwork(Network network, CloudStackClient client, BlockUntilJobCompletesAndReturnResult blockUntilJobCompletesAndReturnResult) { AsyncCreateResponse job = client.getAddressClient().associateIPAddressInZone(network.getZoneId(), networkId(network.getId())); PublicIPAddress ip = blockUntilJobCompletesAndReturnResult.<PublicIPAddress> apply(job); assert ip.getZoneId().equals(network.getZoneId()); return ip; }
public static PublicIPAddress associateIPAddressInNetwork(Network network, CloudStackApi client, BlockUntilJobCompletesAndReturnResult blockUntilJobCompletesAndReturnResult) { AsyncCreateResponse job = client.getAddressApi().associateIPAddressInZone(network.getZoneId(), networkId(network.getId())); PublicIPAddress ip = blockUntilJobCompletesAndReturnResult.<PublicIPAddress> apply(job); assert ip.getZoneId().equals(network.getZoneId()); return ip; }
public void testApply() { String id = "1"; String jobId = "2"; CloudStackClient client = createMock(CloudStackClient.class); Predicate<String> jobComplete = Predicates.alwaysTrue(); AsyncJobClient jobClient = createMock(AsyncJobClient.class); expect(client.getAsyncJobClient()).andReturn(jobClient).atLeastOnce(); expect(jobClient.getAsyncJob(jobId)).andReturn(AsyncJob.builder().id(jobId).result("foo").build()).atLeastOnce(); replay(client); replay(jobClient); assertEquals( new BlockUntilJobCompletesAndReturnResult(client, jobComplete).<String>apply(AsyncCreateResponse.builder().id(id).jobId( jobId).build()), "foo"); verify(client); verify(jobClient); }
public void testAssociateWorks() throws SecurityException, NoSuchMethodException { // create mocks CloudStackClient client = createMock(CloudStackClient.class); BlockUntilJobCompletesAndReturnResult blockUntilJobCompletesAndReturnResult = createMock(BlockUntilJobCompletesAndReturnResult.class); AddressClient addressClient = createMock(AddressClient.class); expect(client.getAddressClient()).andReturn(addressClient).atLeastOnce(); // no ip addresses available expect(addressClient.listPublicIPAddresses(allocatedOnly(true).networkId(networkId))).andReturn( ImmutableSet.<PublicIPAddress> of()); AsyncCreateResponse job = AsyncCreateResponse.builder().id("1").jobId("2").build(); // make sure we created the job relating to a new ip expect(addressClient.associateIPAddressInZone(zoneId, networkId(networkId))).andReturn(job); expect(blockUntilJobCompletesAndReturnResult.apply(job)).andReturn(address); replay(client); replay(addressClient); replay(blockUntilJobCompletesAndReturnResult); assertEquals( new ReuseOrAssociateNewPublicIPAddress(client, blockUntilJobCompletesAndReturnResult).apply(Network .builder().id(networkId).zoneId(zoneId).build()), address); verify(client); verify(addressClient); verify(blockUntilJobCompletesAndReturnResult); }
public void testApply() { String id = "1"; String jobId = "2"; CloudStackApi client = createMock(CloudStackApi.class); Predicate<String> jobComplete = Predicates.alwaysTrue(); AsyncJobApi jobClient = createMock(AsyncJobApi.class); expect(client.getAsyncJobApi()).andReturn(jobClient).atLeastOnce(); expect(jobClient.getAsyncJob(jobId)).andReturn(AsyncJob.builder().id(jobId).result("foo").build()).atLeastOnce(); replay(client); replay(jobClient); assertEquals( new BlockUntilJobCompletesAndReturnResult(client, jobComplete).<String>apply(AsyncCreateResponse.builder().id(id).jobId( jobId).build()), "foo"); verify(client); verify(jobClient); }
@Test(expectedExceptions = IllegalStateException.class) public void testJobDoesntCompleteThrowsIllegalStateException() { String id = "1"; String jobId = "2"; CloudStackClient client = createMock(CloudStackClient.class); // the alwaysfalse predicate should blow up with IllegalStateException Predicate<String> jobComplete = Predicates.alwaysFalse(); AsyncJobClient jobClient = createMock(AsyncJobClient.class); expect(client.getAsyncJobClient()).andReturn(jobClient).atLeastOnce(); expect(jobClient.getAsyncJob(jobId)).andReturn(AsyncJob.builder().id(jobId).result("foo").build()).atLeastOnce(); replay(client); replay(jobClient); assertEquals( new BlockUntilJobCompletesAndReturnResult(client, jobComplete).<String>apply( AsyncCreateResponse.builder().id(id).jobId(jobId).build()), "foo"); verify(client); verify(jobClient); }
@Test(expectedExceptions = IllegalStateException.class) public void testJobDoesntCompleteThrowsIllegalStateException() { String id = "1"; String jobId = "2"; CloudStackApi client = createMock(CloudStackApi.class); // the alwaysfalse predicate should blow up with IllegalStateException Predicate<String> jobComplete = Predicates.alwaysFalse(); AsyncJobApi jobClient = createMock(AsyncJobApi.class); expect(client.getAsyncJobApi()).andReturn(jobClient).atLeastOnce(); expect(jobClient.getAsyncJob(jobId)).andReturn(AsyncJob.builder().id(jobId).result("foo").build()).atLeastOnce(); replay(client); replay(jobClient); assertEquals( new BlockUntilJobCompletesAndReturnResult(client, jobComplete).<String>apply( AsyncCreateResponse.builder().id(id).jobId(jobId).build()), "foo"); verify(client); verify(jobClient); }
public void testAssociateWorks() throws SecurityException, NoSuchMethodException { // create mocks CloudStackApi client = createMock(CloudStackApi.class); BlockUntilJobCompletesAndReturnResult blockUntilJobCompletesAndReturnResult = createMock(BlockUntilJobCompletesAndReturnResult.class); AddressApi addressClient = createMock(AddressApi.class); expect(client.getAddressApi()).andReturn(addressClient).atLeastOnce(); // no ip addresses available expect(addressClient.listPublicIPAddresses(allocatedOnly(true).networkId(networkId))).andReturn( ImmutableSet.<PublicIPAddress> of()); AsyncCreateResponse job = AsyncCreateResponse.builder().id("1").jobId("2").build(); // make sure we created the job relating to a new ip expect(addressClient.associateIPAddressInZone(zoneId, networkId(networkId))).andReturn(job); expect(blockUntilJobCompletesAndReturnResult.apply(job)).andReturn(address); replay(client); replay(addressClient); replay(blockUntilJobCompletesAndReturnResult); assertEquals( new ReuseOrAssociateNewPublicIPAddress(client, blockUntilJobCompletesAndReturnResult).apply(Network .builder().id(networkId).zoneId(zoneId).build()), address); verify(client); verify(addressClient); verify(blockUntilJobCompletesAndReturnResult); }
@Test(expectedExceptions = UncheckedExecutionException.class) public void testJobWithErrorThrowsUncheckedExecutionException() { String id = "1"; String jobId = "2"; CloudStackClient client = createMock(CloudStackClient.class); Predicate<String> jobComplete = Predicates.alwaysTrue(); AsyncJobClient jobClient = createMock(AsyncJobClient.class); expect(client.getAsyncJobClient()).andReturn(jobClient).atLeastOnce(); expect(jobClient.getAsyncJob(jobId)).andReturn( AsyncJob.builder().id(jobId) .error(AsyncJobError.builder().errorCode(ErrorCode.INTERNAL_ERROR).errorText("ERRROR").build()) .result("foo").build()) .atLeastOnce(); replay(client); replay(jobClient); assertEquals( new BlockUntilJobCompletesAndReturnResult(client, jobComplete).<String>apply( AsyncCreateResponse.builder().id(id).jobId(jobId).build()), "foo"); verify(client); verify(jobClient); } }
@Test(expectedExceptions = UncheckedExecutionException.class) public void testJobWithErrorThrowsUncheckedExecutionException() { String id = "1"; String jobId = "2"; CloudStackApi client = createMock(CloudStackApi.class); Predicate<String> jobComplete = Predicates.alwaysTrue(); AsyncJobApi jobClient = createMock(AsyncJobApi.class); expect(client.getAsyncJobApi()).andReturn(jobClient).atLeastOnce(); expect(jobClient.getAsyncJob(jobId)).andReturn( AsyncJob.builder().id(jobId) .error(AsyncJobError.builder().errorCode(ErrorCode.INTERNAL_ERROR).errorText("ERRROR").build()) .result("foo").build()) .atLeastOnce(); replay(client); replay(jobClient); assertEquals( new BlockUntilJobCompletesAndReturnResult(client, jobComplete).<String>apply( AsyncCreateResponse.builder().id(id).jobId(jobId).build()), "foo"); verify(client); verify(jobClient); } }
AsyncCreateResponse job = client.getVirtualMachineClient().deployVirtualMachineInZone(zoneId, serviceOfferingId, templateId, options); VirtualMachine vm = blockUntilJobCompletesAndReturnResult.<VirtualMachine>apply(job); logger.debug("--- virtualmachine: %s", vm); LoginCredentials credentials = null;
AsyncCreateResponse job = client.getVirtualMachineClient().deployVirtualMachineInZone(zoneId, serviceOfferingId, templateId, options); VirtualMachine vm = blockUntilJobCompletesAndReturnResult.<VirtualMachine>apply(job); logger.debug("--- virtualmachine: %s", vm); LoginCredentials credentials = null;
.displayText(cloneTemplate.getName()) .build(), options); Template newTemplate = blockUntilJobCompletesAndReturnResult.<Template>apply(templateJob);