@Override public int[] getInboundPorts() { return delegate.getInboundPorts(); }
@Override public int[] getInboundPorts() { return delegate.getInboundPorts(); }
@Override public int[] getInboundPorts() { return delegate.getInboundPorts(); }
@Override public int[] getInboundPorts() { return delegate.getInboundPorts(); }
@VisibleForTesting public Set<String> getSecurityGroupsForTagAndOptions(String region, @Nullable String group, @Nullable String vpcId, TemplateOptions options) { Builder<String> groups = ImmutableSet.builder(); if (group != null) { String markerGroup = namingConvention.create().sharedNameForGroup(group); if (userSpecifiedTheirOwnGroups(options)) { groups.addAll(EC2TemplateOptions.class.cast(options).getGroups()); } else { RegionNameAndIngressRules regionNameAndIngressRulesForMarkerGroup = new RegionNameAndIngressRules(region, markerGroup, options .getInboundPorts(), true, vpcId); // this will create if not yet exists. groups.add(securityGroupMap.getUnchecked(regionNameAndIngressRulesForMarkerGroup)); } } return groups.build(); }
@VisibleForTesting public Set<String> getSecurityGroupsForTagAndOptions(String region, @Nullable String group, @Nullable String vpcId, TemplateOptions options) { Builder<String> groups = ImmutableSet.builder(); if (group != null) { String markerGroup = namingConvention.create().sharedNameForGroup(group); if (userSpecifiedTheirOwnGroups(options)) { groups.addAll(EC2TemplateOptions.class.cast(options).getGroups()); } else { RegionNameAndIngressRules regionNameAndIngressRulesForMarkerGroup = new RegionNameAndIngressRules(region, markerGroup, options .getInboundPorts(), true, vpcId); // this will create if not yet exists. groups.add(securityGroupMap.getUnchecked(regionNameAndIngressRulesForMarkerGroup)); } } return groups.build(); }
protected String makeNonTrivialArgumentsString() { String s = super.makeNonTrivialArgumentsString(); TemplateOptions aggr = computeAggregatedOptions(false); if (aggr.getInboundPorts().length>0) s = "ports="+Ints.asList(aggr.getInboundPorts())+(s!=null && s.length()>0 ? ", "+s : ""); if (!aggr.getUserMetadata().isEmpty()) s = "metadata="+aggr.getUserMetadata()+(s!=null && s.length()>0 ? ", "+s : ""); if (!aggr.getTags().isEmpty()) s = "tags="+aggr.getTags()+(s!=null && s.length()>0 ? ", "+s : ""); return s; }
@VisibleForTesting public Set<String> getSecurityGroupsForTagAndOptions(String region, @Nullable String group, @Nullable String vpcId, TemplateOptions options) { Builder<String> groups = ImmutableSet.builder(); if (group != null) { String markerGroup = namingConvention.create().sharedNameForGroup(group); if (userSpecifiedTheirOwnGroups(options)) { groups.addAll(EC2TemplateOptions.class.cast(options).getGroups()); } else { RegionNameAndIngressRules regionNameAndIngressRulesForMarkerGroup = new RegionNameAndIngressRules(region, markerGroup, options .getInboundPorts(), true, vpcId); // this will create if not yet exists. groups.add(securityGroupMap.getUnchecked(regionNameAndIngressRulesForMarkerGroup)); } } return groups.build(); }
@Test public void testinboundPorts() { TemplateOptions options = new TemplateOptions(); options.inboundPorts(22, 30); assertEquals(options.getInboundPorts()[0], 22); assertEquals(options.getInboundPorts()[1], 30); }
@Test public void testinboundPortsStatic() { TemplateOptions options = inboundPorts(22, 30); assertEquals(options.toString(), "{inboundPorts=[22, 30]}"); assertEquals(options.getInboundPorts()[0], 22); assertEquals(options.getInboundPorts()[1], 30); }
@Test public void testDefaultOpen22() { TemplateOptions options = new TemplateOptions(); assertEquals(options.getInboundPorts()[0], 22); }
@Test public void testinboundPorts() { TemplateOptions options = new TemplateOptions(); options.inboundPorts(22, 30); assertEquals(options.getInboundPorts()[0], 22); assertEquals(options.getInboundPorts()[1], 30); }
@Test public void testDefaultOpen22() { TemplateOptions options = new TemplateOptions(); assertEquals(options.getInboundPorts()[0], 22); }
@Test public void testinboundPortsStatic() { TemplateOptions options = inboundPorts(22, 30); assertEquals(options.toString(), "{inboundPorts=[22, 30]}"); assertEquals(options.getInboundPorts()[0], 22); assertEquals(options.getInboundPorts()[1], 30); }
@BeforeMethod(alwaysRun = true) public void setUp() { sgCustomizer = mock(JcloudsLocationSecurityGroupCustomizer.class); customizer = new TestSharedLocationSecurityGroupCustomizer(); location = mock(Location.class); securityApi = mock(SecurityGroupExtension.class); computeService = mock(ComputeService.class, Answers.RETURNS_DEEP_STUBS.get()); mockTemplate = mock(Template.class); mockOptions = mock(TemplateOptions.class); when(computeService.getSecurityGroupExtension()).thenReturn(Optional.of(securityApi)); when(mockTemplate.getOptions()).thenReturn(mockOptions); when(mockOptions.getInboundPorts()).thenReturn(new int[]{}); }
@Test public void testInboundPortsAddedToPermissions() { when(mockOptions.getInboundPorts()).thenReturn(new int[]{5}); when(sgCustomizer.getBrooklynCidrBlock()).thenReturn("10.10.10.10/24"); customizer.customize(jcloudsLocation, computeService, mockTemplate); customizer.customize(jcloudsLocation, computeService, mock(JcloudsMachineLocation.class)); assertPermissionsAdded(5, 5, IpProtocol.TCP); }
@Override public NodeMetadata createNodeWithGroupEncodedIntoName(String group, String name, Template template) { InstantiateVAppTemplateOptions options = getOptions.apply(template); NodeAndInitialCredentials<VApp> from = computeClient.startAndReturnCredentials(URI.create(template.getLocation().getId()), URI.create(template .getImage().getId()), name, options, template.getOptions().getInboundPorts()); LoginCredentials fromNode = from.getCredentials(); if (credentialStore.containsKey("group#" + group)) { fromNode = fromNode == null ? LoginCredentials.fromCredentials(credentialStore.get("group#" + group)) : fromNode.toBuilder().privateKey(credentialStore.get("group#" + group).credential).build(); } LoginCredentials creds = prioritizeCredentialsFromTemplate.apply(template, fromNode); if (creds != null) credentialStore.put("node#" + from.getNodeId(), creds); return vAppToNodeMetadata.apply(from.getNode()); }
@Override public NodeMetadata addNodeWithTag(String tag, String name, Template template) { InstantiateVAppTemplateOptions options = processorCount((int) getCores(template.getHardware())).memory( template.getHardware().getRam()).disk( (long) ((template.getHardware().getVolumes().get(0).getSize()) * 1024 * 1024l)); if (!template.getOptions().shouldBlockUntilRunning()) options.block(false); VCloudExpressVApp vApp = computeClient.start(URI.create(template.getLocation().getId()), URI.create(template.getImage().getId()), name, options, template.getOptions().getInboundPorts()); return vAppToNodeMetadata.apply(vApp); }
@Test(groups={"Live", "Live-sanity"}) public void testCreateWithInboundPortsOverride() { BailOutJcloudsLocation jcloudsLocation = BailOutJcloudsLocation.newBailOutJcloudsLocationForLiveTest(managementContext); jcloudsLocation = (BailOutJcloudsLocation) jcloudsLocation.newSubLocation(MutableMap.of()); jcloudsLocation.tryObtainAndCheck(MutableMap.of(INBOUND_PORTS, "[23, 81, 9998]"), templateCheckerFor("[23, 81, 9998]")); int[] ports = new int[] {23, 81, 9998}; Assert.assertEquals(jcloudsLocation.getTemplate().getOptions().getInboundPorts(), ports); }
@Test(groups={"Live", "Live-sanity"}) public void testCreateWithInboundPorts() { BailOutJcloudsLocation jcloudsLocation = BailOutJcloudsLocation.newBailOutJcloudsLocationForLiveTest(managementContext); jcloudsLocation = (BailOutJcloudsLocation) jcloudsLocation.newSubLocation(MutableMap.of()); jcloudsLocation.tryObtainAndCheck(MutableMap.of(), templateCheckerFor("[22, 80, 9999]")); int[] ports = new int[] {22, 80, 9999}; Assert.assertEquals(jcloudsLocation.getTemplate().getOptions().getInboundPorts(), ports); }