Search in sources :

Example 6 with NetworkSecurityGroupInner

use of com.microsoft.azure.management.network.implementation.NetworkSecurityGroupInner in project photon-model by vmware.

the class AzureSecurityGroupServiceTest method testCreateSecurityGroupFailures.

@Test
public void testCreateSecurityGroupFailures() throws Throwable {
    if (!this.isMock) {
        // test invalid security rule name
        SecurityGroupState securityGroupState = provisionSecurityGroup(buildInvalidNameRules(), buildNonDefaultRules(), TaskStage.FAILED);
        assertNotNull(securityGroupState.id);
        assertNotEquals(securityGroupState.id, this.securityGroupName);
        // Verify that the security group was created without any rules.
        NetworkSecurityGroupInner sgResponse = this.securityGroupsClient.getByResourceGroup(this.rgName, this.securityGroupName);
        assertEquals(this.securityGroupName, sgResponse.name());
        assertEquals(securityGroupState.id, sgResponse.id());
        assertEquals(sgResponse.securityRules().size(), 0);
        // delete the security group
        startSecurityGroupProvisioning(InstanceRequestType.DELETE, securityGroupState, TaskStage.FINISHED);
    }
}
Also used : NetworkSecurityGroupInner(com.microsoft.azure.management.network.implementation.NetworkSecurityGroupInner) AzureTestUtil.getSecurityGroupState(com.vmware.photon.controller.model.adapters.azure.instance.AzureTestUtil.getSecurityGroupState) SecurityGroupState(com.vmware.photon.controller.model.resources.SecurityGroupService.SecurityGroupState) AzureBaseTest(com.vmware.photon.controller.model.adapters.azure.base.AzureBaseTest) Test(org.junit.Test)

Example 7 with NetworkSecurityGroupInner

use of com.microsoft.azure.management.network.implementation.NetworkSecurityGroupInner in project photon-model by vmware.

the class AzureSecurityGroupServiceTest method testDeleteSecurityGroup.

@Test
public void testDeleteSecurityGroup() throws Throwable {
    SecurityGroupState securityGroupState = provisionSecurityGroup(new ArrayList<>(), new ArrayList<>(), TaskStage.FINISHED);
    startSecurityGroupProvisioning(InstanceRequestType.DELETE, securityGroupState, TaskStage.FINISHED);
    // verify security group state was deleted
    try {
        getSecurityGroupState(this.host, securityGroupState.documentSelfLink);
    } catch (Exception e) {
        assertTrue(e instanceof ServiceNotFoundException);
    }
    if (!this.isMock) {
        // Verify that the security group was deleted from Azure.
        NetworkSecurityGroupInner sgResponse = this.securityGroupsClient.getByResourceGroup(this.rgName, this.securityGroupName);
        if (sgResponse != null) {
            fail("Security group should not exist in Azure.");
        }
    }
}
Also used : NetworkSecurityGroupInner(com.microsoft.azure.management.network.implementation.NetworkSecurityGroupInner) AzureTestUtil.getSecurityGroupState(com.vmware.photon.controller.model.adapters.azure.instance.AzureTestUtil.getSecurityGroupState) SecurityGroupState(com.vmware.photon.controller.model.resources.SecurityGroupService.SecurityGroupState) ServiceNotFoundException(com.vmware.xenon.common.ServiceHost.ServiceNotFoundException) ServiceNotFoundException(com.vmware.xenon.common.ServiceHost.ServiceNotFoundException) AzureBaseTest(com.vmware.photon.controller.model.adapters.azure.base.AzureBaseTest) Test(org.junit.Test)

Example 8 with NetworkSecurityGroupInner

use of com.microsoft.azure.management.network.implementation.NetworkSecurityGroupInner in project photon-model by vmware.

the class AzureSecurityGroupServiceTest method testCreateSecurityGroupWithNonDefaultRules.

@Test
public void testCreateSecurityGroupWithNonDefaultRules() throws Throwable {
    SecurityGroupState securityGroupState = provisionSecurityGroup(buildNonDefaultRules(), buildNonDefaultRules(), TaskStage.FINISHED);
    assertNotNull(securityGroupState.id);
    assertNotEquals(securityGroupState.id, this.securityGroupName);
    if (!this.isMock) {
        // Verify that the security group was created.
        NetworkSecurityGroupInner sgResponse = this.securityGroupsClient.getByResourceGroup(this.rgName, this.securityGroupName);
        assertEquals(this.securityGroupName, sgResponse.name());
        assertEquals(securityGroupState.id, sgResponse.id());
        assertEquals(sgResponse.securityRules().size(), 2 * securityGroupState.ingress.size());
        validateAzureSecurityRules(sgResponse.securityRules(), securityGroupState.ingress.size());
        // delete the security group
        startSecurityGroupProvisioning(InstanceRequestType.DELETE, securityGroupState, TaskStage.FINISHED);
    }
}
Also used : NetworkSecurityGroupInner(com.microsoft.azure.management.network.implementation.NetworkSecurityGroupInner) AzureTestUtil.getSecurityGroupState(com.vmware.photon.controller.model.adapters.azure.instance.AzureTestUtil.getSecurityGroupState) SecurityGroupState(com.vmware.photon.controller.model.resources.SecurityGroupService.SecurityGroupState) AzureBaseTest(com.vmware.photon.controller.model.adapters.azure.base.AzureBaseTest) Test(org.junit.Test)

Example 9 with NetworkSecurityGroupInner

use of com.microsoft.azure.management.network.implementation.NetworkSecurityGroupInner in project photon-model by vmware.

the class AzureSecurityGroupServiceTest method testCreateSecurityGroupWithDefaultRules.

@Test
public void testCreateSecurityGroupWithDefaultRules() throws Throwable {
    SecurityGroupState securityGroupState = provisionSecurityGroup(buildDefaultRules(), buildDefaultRules(), TaskStage.FINISHED);
    assertNotNull(securityGroupState.id);
    assertNotEquals(securityGroupState.id, this.securityGroupName);
    if (!this.isMock) {
        // Verify that the security group was created.
        NetworkSecurityGroupInner sgResponse = this.securityGroupsClient.getByResourceGroup(this.rgName, this.securityGroupName);
        assertEquals(this.securityGroupName, sgResponse.name());
        assertEquals(securityGroupState.id, sgResponse.id());
        assertEquals(sgResponse.securityRules().size(), securityGroupState.ingress.size());
        validateAzureSecurityRules(sgResponse.securityRules(), securityGroupState.ingress.size() - 1);
        // delete the security group
        startSecurityGroupProvisioning(InstanceRequestType.DELETE, securityGroupState, TaskStage.FINISHED);
    }
}
Also used : NetworkSecurityGroupInner(com.microsoft.azure.management.network.implementation.NetworkSecurityGroupInner) AzureTestUtil.getSecurityGroupState(com.vmware.photon.controller.model.adapters.azure.instance.AzureTestUtil.getSecurityGroupState) SecurityGroupState(com.vmware.photon.controller.model.resources.SecurityGroupService.SecurityGroupState) AzureBaseTest(com.vmware.photon.controller.model.adapters.azure.base.AzureBaseTest) Test(org.junit.Test)

Example 10 with NetworkSecurityGroupInner

use of com.microsoft.azure.management.network.implementation.NetworkSecurityGroupInner in project photon-model by vmware.

the class AzureLoadBalancerService method updateSecurityGroupRules.

/**
 * Update isolation security group with rule to allow traffic on load balancing ports for VMs
 * being load balanced
 *
 * @param context Azure load balancer context
 * @return DeferredResult
 */
private DeferredResult<AzureLoadBalancerContext> updateSecurityGroupRules(AzureLoadBalancerContext context) {
    if (CollectionUtils.isEmpty(context.securityGroupInners)) {
        return DeferredResult.completed(context);
    }
    // Add security group firewall rules to allow traffic to flow through load balancer routes
    updateSecurityRules(context);
    NetworkSecurityGroupsInner azureSecurityGroupClient = context.azureSdkClients.getNetworkManagementClientImpl().networkSecurityGroups();
    List<DeferredResult<NetworkSecurityGroupInner>> networkSecurityGroupInnerList = context.securityGroupInners.stream().map(networkSecurityGroupInner -> {
        final String msg = "Updating security group rules for [" + networkSecurityGroupInner.name() + "] for load balancer [" + context.loadBalancerStateExpanded.name + "].";
        logInfo(() -> msg);
        return AzureSecurityGroupUtils.createOrUpdateSecurityGroup(this, azureSecurityGroupClient, AzureUtils.getResourceGroupName(networkSecurityGroupInner.id()), networkSecurityGroupInner.name(), networkSecurityGroupInner, msg);
    }).collect(Collectors.toList());
    return DeferredResult.allOf(networkSecurityGroupInnerList).thenApply(ignored -> context);
}
Also used : SecurityRuleProtocol(com.microsoft.azure.management.network.SecurityRuleProtocol) NetworkManagementClientImpl(com.microsoft.azure.management.network.implementation.NetworkManagementClientImpl) IPAllocationMethod(com.microsoft.azure.management.network.IPAllocationMethod) AzureUriPaths(com.vmware.photon.controller.model.adapters.azure.AzureUriPaths) StringUtils(org.apache.commons.lang3.StringUtils) LoadBalancingRuleInner(com.microsoft.azure.management.network.implementation.LoadBalancingRuleInner) FrontendIPConfigurationInner(com.microsoft.azure.management.network.implementation.FrontendIPConfigurationInner) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) BackendAddressPoolInner(com.microsoft.azure.management.network.implementation.BackendAddressPoolInner) URI(java.net.URI) AssertUtil(com.vmware.photon.controller.model.util.AssertUtil) SecurityRuleDirection(com.microsoft.azure.management.network.SecurityRuleDirection) ProbeInner(com.microsoft.azure.management.network.implementation.ProbeInner) HealthCheckConfiguration(com.vmware.photon.controller.model.resources.LoadBalancerDescriptionService.LoadBalancerDescription.HealthCheckConfiguration) NetworkInterfaceState(com.vmware.photon.controller.model.resources.NetworkInterfaceService.NetworkInterfaceState) StatelessService(com.vmware.xenon.common.StatelessService) LoadBalancersInner(com.microsoft.azure.management.network.implementation.LoadBalancersInner) Set(java.util.Set) UUID(java.util.UUID) SecurityRuleAccess(com.microsoft.azure.management.network.SecurityRuleAccess) Collectors(java.util.stream.Collectors) AzureProvisioningCallback(com.vmware.photon.controller.model.adapters.azure.utils.AzureProvisioningCallback) List(java.util.List) AzureUtils(com.vmware.photon.controller.model.adapters.azure.utils.AzureUtils) AzureSecurityGroupUtils(com.vmware.photon.controller.model.adapters.azure.utils.AzureSecurityGroupUtils) NetworkSecurityGroupsInner(com.microsoft.azure.management.network.implementation.NetworkSecurityGroupsInner) DeferredResult(com.vmware.xenon.common.DeferredResult) UriUtils(com.vmware.xenon.common.UriUtils) LoadBalancerInner(com.microsoft.azure.management.network.implementation.LoadBalancerInner) NetworkInterfacesInner(com.microsoft.azure.management.network.implementation.NetworkInterfacesInner) Optional(java.util.Optional) NetworkSecurityGroupInner(com.microsoft.azure.management.network.implementation.NetworkSecurityGroupInner) AzureProvisioningCallbackWithRetry(com.vmware.photon.controller.model.adapters.azure.utils.AzureProvisioningCallbackWithRetry) Default(com.vmware.photon.controller.model.adapters.azure.utils.AzureDeferredResultServiceCallback.Default) SubResource(com.microsoft.azure.SubResource) RouteConfiguration(com.vmware.photon.controller.model.resources.LoadBalancerDescriptionService.LoadBalancerDescription.RouteConfiguration) TransportProtocol(com.microsoft.azure.management.network.TransportProtocol) ArrayList(java.util.ArrayList) SecurityGroupState(com.vmware.photon.controller.model.resources.SecurityGroupService.SecurityGroupState) HashSet(java.util.HashSet) Lists(com.google.common.collect.Lists) AzureBaseAdapterContext(com.vmware.photon.controller.model.adapters.azure.utils.AzureBaseAdapterContext) CollectionUtils(org.apache.commons.collections.CollectionUtils) ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) PublicIPAddressesInner(com.microsoft.azure.management.network.implementation.PublicIPAddressesInner) PublicIPAddressInner(com.microsoft.azure.management.network.implementation.PublicIPAddressInner) NetworkInterfaceIPConfigurationInner(com.microsoft.azure.management.network.implementation.NetworkInterfaceIPConfigurationInner) ServiceCallback(com.microsoft.rest.ServiceCallback) LoadBalancerStateExpanded(com.vmware.photon.controller.model.resources.LoadBalancerService.LoadBalancerStateExpanded) Operation(com.vmware.xenon.common.Operation) SecurityGroupService(com.vmware.photon.controller.model.resources.SecurityGroupService) BaseAdapterStage(com.vmware.photon.controller.model.adapters.util.BaseAdapterContext.BaseAdapterStage) ProbeProtocol(com.microsoft.azure.management.network.ProbeProtocol) AzureDeferredResultServiceCallback(com.vmware.photon.controller.model.adapters.azure.utils.AzureDeferredResultServiceCallback) SecurityRuleInner(com.microsoft.azure.management.network.implementation.SecurityRuleInner) LoadBalancerInstanceRequest(com.vmware.photon.controller.model.adapterapi.LoadBalancerInstanceRequest) Comparator(java.util.Comparator) NetworkInterfaceInner(com.microsoft.azure.management.network.implementation.NetworkInterfaceInner) PhotonModelUriUtils.createInventoryUri(com.vmware.photon.controller.model.util.PhotonModelUriUtils.createInventoryUri) NetworkSecurityGroupsInner(com.microsoft.azure.management.network.implementation.NetworkSecurityGroupsInner) DeferredResult(com.vmware.xenon.common.DeferredResult)

Aggregations

NetworkSecurityGroupInner (com.microsoft.azure.management.network.implementation.NetworkSecurityGroupInner)13 SecurityGroupState (com.vmware.photon.controller.model.resources.SecurityGroupService.SecurityGroupState)9 NetworkInterfaceInner (com.microsoft.azure.management.network.implementation.NetworkInterfaceInner)4 NetworkManagementClientImpl (com.microsoft.azure.management.network.implementation.NetworkManagementClientImpl)4 NetworkSecurityGroupsInner (com.microsoft.azure.management.network.implementation.NetworkSecurityGroupsInner)4 PublicIPAddressInner (com.microsoft.azure.management.network.implementation.PublicIPAddressInner)4 AzureBaseTest (com.vmware.photon.controller.model.adapters.azure.base.AzureBaseTest)4 AzureTestUtil.getSecurityGroupState (com.vmware.photon.controller.model.adapters.azure.instance.AzureTestUtil.getSecurityGroupState)4 AzureDeferredResultServiceCallback (com.vmware.photon.controller.model.adapters.azure.utils.AzureDeferredResultServiceCallback)4 AzureSecurityGroupUtils (com.vmware.photon.controller.model.adapters.azure.utils.AzureSecurityGroupUtils)4 AzureUtils (com.vmware.photon.controller.model.adapters.azure.utils.AzureUtils)4 DeferredResult (com.vmware.xenon.common.DeferredResult)4 ArrayList (java.util.ArrayList)4 List (java.util.List)4 Collectors (java.util.stream.Collectors)4 Test (org.junit.Test)4 SubResource (com.microsoft.azure.SubResource)3 VirtualMachineInner (com.microsoft.azure.management.compute.implementation.VirtualMachineInner)3 IPAllocationMethod (com.microsoft.azure.management.network.IPAllocationMethod)3 NetworkInterfaceIPConfigurationInner (com.microsoft.azure.management.network.implementation.NetworkInterfaceIPConfigurationInner)3