Search in sources :

Example 11 with AzureClient

use of com.sequenceiq.cloudbreak.cloud.azure.client.AzureClient in project cloudbreak by hortonworks.

the class AzureInstanceConnector method start.

@Override
public List<CloudVmInstanceStatus> start(AuthenticatedContext ac, List<CloudResource> resources, List<CloudInstance> vms) {
    String stackName = armTemplateUtils.getStackName(ac.getCloudContext());
    List<CloudVmInstanceStatus> statuses = new ArrayList<>();
    for (CloudInstance vm : vms) {
        try {
            AzureClient azureClient = ac.getParameter(AzureClient.class);
            azureClient.startVirtualMachine(stackName, vm.getInstanceId());
            statuses.add(new CloudVmInstanceStatus(vm, InstanceStatus.IN_PROGRESS));
        } catch (RuntimeException e) {
            statuses.add(new CloudVmInstanceStatus(vm, InstanceStatus.FAILED, e.getMessage()));
        }
    }
    return statuses;
}
Also used : AzureClient(com.sequenceiq.cloudbreak.cloud.azure.client.AzureClient) CloudVmInstanceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus) ArrayList(java.util.ArrayList) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance)

Example 12 with AzureClient

use of com.sequenceiq.cloudbreak.cloud.azure.client.AzureClient in project cloudbreak by hortonworks.

the class AzureInstanceConnector method check.

@Override
public List<CloudVmInstanceStatus> check(AuthenticatedContext ac, List<CloudInstance> vms) {
    List<CloudVmInstanceStatus> statuses = new ArrayList<>();
    String stackName = armTemplateUtils.getStackName(ac.getCloudContext());
    for (CloudInstance vm : vms) {
        try {
            AzureClient azureClient = ac.getParameter(AzureClient.class);
            boolean virtualMachineExists = azureClient.isVirtualMachineExists(stackName, vm.getInstanceId());
            if (virtualMachineExists) {
                PowerState virtualMachinePowerState = azureClient.getVirtualMachinePowerState(stackName, vm.getInstanceId());
                statuses.add(new CloudVmInstanceStatus(vm, AzureInstanceStatus.get(virtualMachinePowerState)));
            } else {
                statuses.add(new CloudVmInstanceStatus(vm, InstanceStatus.TERMINATED));
            }
        } catch (CloudException e) {
            if (e.body() != null && "ResourceNotFound".equals(e.body().code())) {
                statuses.add(new CloudVmInstanceStatus(vm, InstanceStatus.TERMINATED));
            } else {
                statuses.add(new CloudVmInstanceStatus(vm, InstanceStatus.UNKNOWN));
            }
        } catch (RuntimeException ignored) {
            statuses.add(new CloudVmInstanceStatus(vm, InstanceStatus.UNKNOWN));
        }
    }
    return statuses;
}
Also used : AzureClient(com.sequenceiq.cloudbreak.cloud.azure.client.AzureClient) CloudVmInstanceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus) ArrayList(java.util.ArrayList) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) CloudException(com.microsoft.azure.CloudException) PowerState(com.microsoft.azure.management.compute.PowerState)

Example 13 with AzureClient

use of com.sequenceiq.cloudbreak.cloud.azure.client.AzureClient in project cloudbreak by hortonworks.

the class AzurePlatformResources method regions.

@Override
@Cacheable(cacheNames = "cloudResourceRegionCache", key = "#cloudCredential?.id")
public CloudRegions regions(CloudCredential cloudCredential, Region region, Map<String, String> filters) {
    AzureClient client = azureClientService.getClient(cloudCredential);
    Map<Region, List<AvailabilityZone>> cloudRegions = new HashMap<>();
    Map<Region, String> displayNames = new HashMap<>();
    String defaultRegion = armZoneParameterDefault;
    for (com.microsoft.azure.management.resources.fluentcore.arm.Region azureRegion : client.getRegion(region)) {
        cloudRegions.put(region(azureRegion.label()), new ArrayList<>());
        displayNames.put(region(azureRegion.label()), azureRegion.label());
    }
    if (region != null && !Strings.isNullOrEmpty(region.value())) {
        defaultRegion = region.value();
    }
    return new CloudRegions(cloudRegions, displayNames, defaultRegion);
}
Also used : HashMap(java.util.HashMap) CloudRegions(com.sequenceiq.cloudbreak.cloud.model.CloudRegions) AzureClient(com.sequenceiq.cloudbreak.cloud.azure.client.AzureClient) Region(com.sequenceiq.cloudbreak.cloud.model.Region) ArrayList(java.util.ArrayList) List(java.util.List) Cacheable(org.springframework.cache.annotation.Cacheable)

Example 14 with AzureClient

use of com.sequenceiq.cloudbreak.cloud.azure.client.AzureClient in project cloudbreak by hortonworks.

the class AzurePlatformResources method securityGroups.

@Override
public CloudSecurityGroups securityGroups(CloudCredential cloudCredential, Region region, Map<String, String> filters) {
    AzureClient client = azureClientService.getClient(cloudCredential);
    Map<String, Set<CloudSecurityGroup>> result = new HashMap<>();
    for (NetworkSecurityGroup securityGroup : client.getSecurityGroups().list()) {
        String actualRegion = securityGroup.region().label();
        if (regionMatch(actualRegion, region)) {
            Map<String, Object> properties = new HashMap<>();
            properties.put("resourceGroupName", securityGroup.resourceGroupName());
            properties.put("networkInterfaceIds", securityGroup.networkInterfaceIds());
            CloudSecurityGroup cloudSecurityGroup = new CloudSecurityGroup(securityGroup.name(), securityGroup.id(), properties);
            result.computeIfAbsent(actualRegion, s -> new HashSet<>()).add(cloudSecurityGroup);
        }
    }
    if (result.isEmpty() && Objects.nonNull(region)) {
        result.put(region.value(), new HashSet<>());
    }
    return new CloudSecurityGroups(result);
}
Also used : VolumeParameterType.values(com.sequenceiq.cloudbreak.cloud.model.VolumeParameterType.values) AzureClient(com.sequenceiq.cloudbreak.cloud.azure.client.AzureClient) CloudVmTypes(com.sequenceiq.cloudbreak.cloud.model.CloudVmTypes) CloudIpPools(com.sequenceiq.cloudbreak.cloud.model.CloudIpPools) Region(com.sequenceiq.cloudbreak.cloud.model.Region) Cacheable(org.springframework.cache.annotation.Cacheable) Subnet(com.microsoft.azure.management.network.Subnet) HashMap(java.util.HashMap) CloudGateWays(com.sequenceiq.cloudbreak.cloud.model.CloudGateWays) CloudNetworks(com.sequenceiq.cloudbreak.cloud.model.CloudNetworks) CloudRegions(com.sequenceiq.cloudbreak.cloud.model.CloudRegions) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Inject(javax.inject.Inject) Value(org.springframework.beans.factory.annotation.Value) AvailabilityZone(com.sequenceiq.cloudbreak.cloud.model.AvailabilityZone) Strings(com.google.common.base.Strings) Network(com.microsoft.azure.management.network.Network) CloudSshKeys(com.sequenceiq.cloudbreak.cloud.model.CloudSshKeys) Service(org.springframework.stereotype.Service) Map(java.util.Map) PlatformResources(com.sequenceiq.cloudbreak.cloud.PlatformResources) VmTypeMetaBuilder(com.sequenceiq.cloudbreak.cloud.model.VmTypeMeta.VmTypeMetaBuilder) Region.region(com.sequenceiq.cloudbreak.cloud.model.Region.region) Set(java.util.Set) NetworkSecurityGroup(com.microsoft.azure.management.network.NetworkSecurityGroup) CloudAccessConfigs(com.sequenceiq.cloudbreak.cloud.model.CloudAccessConfigs) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) VmType(com.sequenceiq.cloudbreak.cloud.model.VmType) Objects(java.util.Objects) List(java.util.List) VirtualMachineSize(com.microsoft.azure.management.compute.VirtualMachineSize) VolumeParameterType(com.sequenceiq.cloudbreak.cloud.model.VolumeParameterType) CloudSecurityGroups(com.sequenceiq.cloudbreak.cloud.model.CloudSecurityGroups) Entry(java.util.Map.Entry) AzureClientService(com.sequenceiq.cloudbreak.cloud.azure.client.AzureClientService) VolumeParameterConfig(com.sequenceiq.cloudbreak.cloud.model.VolumeParameterConfig) CloudNetwork(com.sequenceiq.cloudbreak.cloud.model.CloudNetwork) MAGNETIC(com.sequenceiq.cloudbreak.cloud.model.VolumeParameterType.MAGNETIC) CloudSecurityGroup(com.sequenceiq.cloudbreak.cloud.model.CloudSecurityGroup) NetworkSecurityGroup(com.microsoft.azure.management.network.NetworkSecurityGroup) HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) AzureClient(com.sequenceiq.cloudbreak.cloud.azure.client.AzureClient) CloudSecurityGroups(com.sequenceiq.cloudbreak.cloud.model.CloudSecurityGroups) CloudSecurityGroup(com.sequenceiq.cloudbreak.cloud.model.CloudSecurityGroup) HashSet(java.util.HashSet)

Example 15 with AzureClient

use of com.sequenceiq.cloudbreak.cloud.azure.client.AzureClient in project cloudbreak by hortonworks.

the class AzurePlatformResources method networks.

@Override
public CloudNetworks networks(CloudCredential cloudCredential, Region region, Map<String, String> filters) {
    AzureClient client = azureClientService.getClient(cloudCredential);
    Map<String, Set<CloudNetwork>> result = new HashMap<>();
    for (Network network : client.getNetworks()) {
        String actualRegion = network.region().label();
        if (regionMatch(actualRegion, region)) {
            Map<String, String> subnets = new HashMap<>();
            for (Entry<String, Subnet> subnet : network.subnets().entrySet()) {
                subnets.put(subnet.getKey(), subnet.getKey());
            }
            Map<String, Object> properties = new HashMap<>();
            properties.put("addressSpaces", network.addressSpaces());
            properties.put("dnsServerIPs", network.dnsServerIPs());
            properties.put("resourceGroupName", network.resourceGroupName());
            CloudNetwork cloudNetwork = new CloudNetwork(network.name(), network.id(), subnets, properties);
            result.computeIfAbsent(actualRegion, s -> new HashSet<>()).add(cloudNetwork);
        }
    }
    if (result.isEmpty() && Objects.nonNull(region)) {
        result.put(region.value(), new HashSet<>());
    }
    return new CloudNetworks(result);
}
Also used : VolumeParameterType.values(com.sequenceiq.cloudbreak.cloud.model.VolumeParameterType.values) AzureClient(com.sequenceiq.cloudbreak.cloud.azure.client.AzureClient) CloudVmTypes(com.sequenceiq.cloudbreak.cloud.model.CloudVmTypes) CloudIpPools(com.sequenceiq.cloudbreak.cloud.model.CloudIpPools) Region(com.sequenceiq.cloudbreak.cloud.model.Region) Cacheable(org.springframework.cache.annotation.Cacheable) Subnet(com.microsoft.azure.management.network.Subnet) HashMap(java.util.HashMap) CloudGateWays(com.sequenceiq.cloudbreak.cloud.model.CloudGateWays) CloudNetworks(com.sequenceiq.cloudbreak.cloud.model.CloudNetworks) CloudRegions(com.sequenceiq.cloudbreak.cloud.model.CloudRegions) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Inject(javax.inject.Inject) Value(org.springframework.beans.factory.annotation.Value) AvailabilityZone(com.sequenceiq.cloudbreak.cloud.model.AvailabilityZone) Strings(com.google.common.base.Strings) Network(com.microsoft.azure.management.network.Network) CloudSshKeys(com.sequenceiq.cloudbreak.cloud.model.CloudSshKeys) Service(org.springframework.stereotype.Service) Map(java.util.Map) PlatformResources(com.sequenceiq.cloudbreak.cloud.PlatformResources) VmTypeMetaBuilder(com.sequenceiq.cloudbreak.cloud.model.VmTypeMeta.VmTypeMetaBuilder) Region.region(com.sequenceiq.cloudbreak.cloud.model.Region.region) Set(java.util.Set) NetworkSecurityGroup(com.microsoft.azure.management.network.NetworkSecurityGroup) CloudAccessConfigs(com.sequenceiq.cloudbreak.cloud.model.CloudAccessConfigs) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) VmType(com.sequenceiq.cloudbreak.cloud.model.VmType) Objects(java.util.Objects) List(java.util.List) VirtualMachineSize(com.microsoft.azure.management.compute.VirtualMachineSize) VolumeParameterType(com.sequenceiq.cloudbreak.cloud.model.VolumeParameterType) CloudSecurityGroups(com.sequenceiq.cloudbreak.cloud.model.CloudSecurityGroups) Entry(java.util.Map.Entry) AzureClientService(com.sequenceiq.cloudbreak.cloud.azure.client.AzureClientService) VolumeParameterConfig(com.sequenceiq.cloudbreak.cloud.model.VolumeParameterConfig) CloudNetwork(com.sequenceiq.cloudbreak.cloud.model.CloudNetwork) MAGNETIC(com.sequenceiq.cloudbreak.cloud.model.VolumeParameterType.MAGNETIC) CloudSecurityGroup(com.sequenceiq.cloudbreak.cloud.model.CloudSecurityGroup) HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) CloudNetworks(com.sequenceiq.cloudbreak.cloud.model.CloudNetworks) AzureClient(com.sequenceiq.cloudbreak.cloud.azure.client.AzureClient) Network(com.microsoft.azure.management.network.Network) CloudNetwork(com.sequenceiq.cloudbreak.cloud.model.CloudNetwork) Subnet(com.microsoft.azure.management.network.Subnet) CloudNetwork(com.sequenceiq.cloudbreak.cloud.model.CloudNetwork) HashSet(java.util.HashSet)

Aggregations

AzureClient (com.sequenceiq.cloudbreak.cloud.azure.client.AzureClient)20 CloudConnectorException (com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException)9 ArrayList (java.util.ArrayList)8 CloudInstance (com.sequenceiq.cloudbreak.cloud.model.CloudInstance)6 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)6 HashMap (java.util.HashMap)6 CloudException (com.microsoft.azure.CloudException)5 AzureCredentialView (com.sequenceiq.cloudbreak.cloud.azure.view.AzureCredentialView)5 CloudVmInstanceStatus (com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus)4 Cacheable (org.springframework.cache.annotation.Cacheable)4 VirtualMachineSize (com.microsoft.azure.management.compute.VirtualMachineSize)3 CloudRegions (com.sequenceiq.cloudbreak.cloud.model.CloudRegions)3 CloudVmTypes (com.sequenceiq.cloudbreak.cloud.model.CloudVmTypes)3 Region (com.sequenceiq.cloudbreak.cloud.model.Region)3 VmType (com.sequenceiq.cloudbreak.cloud.model.VmType)3 VmTypeMetaBuilder (com.sequenceiq.cloudbreak.cloud.model.VmTypeMeta.VmTypeMetaBuilder)3 VolumeParameterType (com.sequenceiq.cloudbreak.cloud.model.VolumeParameterType)3 ActionWentFailException (com.sequenceiq.cloudbreak.service.Retry.ActionWentFailException)3 List (java.util.List)3 Strings (com.google.common.base.Strings)2