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;
}
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;
}
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);
}
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);
}
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);
}
Aggregations