Search in sources :

Example 21 with VirtualMachine

use of com.microsoft.azure.management.compute.VirtualMachine in project cloudbreak by hortonworks.

the class AzureResourceConnector method collectInstanceResourcesToRemove.

private Map<String, Object> collectInstanceResourcesToRemove(AuthenticatedContext ac, CloudStack stack, AzureClient client, AzureCredentialView azureCredentialView, String stackName, CloudInstance instance) {
    String instanceId = instance.getInstanceId();
    Long privateId = instance.getTemplate().getPrivateId();
    AzureDiskType azureDiskType = AzureDiskType.getByValue(instance.getTemplate().getVolumeType());
    String attachedDiskStorageName = azureStorage.getAttachedDiskStorageName(azureStorage.getArmAttachedStorageOption(stack.getParameters()), azureCredentialView, privateId, ac.getCloudContext(), azureDiskType);
    Map<String, Object> resourcesToRemove = new HashMap<>();
    resourcesToRemove.put(ATTACHED_DISK_STORAGE_NAME, attachedDiskStorageName);
    try {
        VirtualMachine virtualMachine = client.getVirtualMachine(stackName, instanceId);
        List<String> networkInterfaceIds = virtualMachine.networkInterfaceIds();
        Collection<String> networkInterfacesNames = new ArrayList<>();
        Collection<String> publicIpAddressNames = new ArrayList<>();
        for (String interfaceId : networkInterfaceIds) {
            NetworkInterface networkInterface = client.getNetworkInterfaceById(interfaceId);
            String interfaceName = networkInterface.name();
            networkInterfacesNames.add(interfaceName);
            Collection<String> ipNames = new HashSet<>();
            for (NicIPConfiguration ipConfiguration : networkInterface.ipConfigurations().values()) {
                if (ipConfiguration.publicIPAddressId() != null && ipConfiguration.getPublicIPAddress().name() != null) {
                    ipNames.add(ipConfiguration.getPublicIPAddress().name());
                }
            }
            publicIpAddressNames.addAll(ipNames);
        }
        resourcesToRemove.put(NETWORK_INTERFACES_NAMES, networkInterfacesNames);
        resourcesToRemove.put(PUBLIC_ADDRESS_NAME, publicIpAddressNames);
        collectRemovableDisks(resourcesToRemove, virtualMachine);
    } catch (CloudException e) {
        if (e.response().code() != AzureConstants.NOT_FOUND) {
            throw new CloudConnectorException(e.body().message(), e);
        }
    } catch (RuntimeException e) {
        throw new CloudConnectorException("can't collect instance resources", e);
    }
    return resourcesToRemove;
}
Also used : HashMap(java.util.HashMap) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) ArrayList(java.util.ArrayList) NetworkInterface(com.microsoft.azure.management.network.NetworkInterface) CloudException(com.microsoft.azure.CloudException) NicIPConfiguration(com.microsoft.azure.management.network.NicIPConfiguration) VirtualMachine(com.microsoft.azure.management.compute.VirtualMachine) HashSet(java.util.HashSet)

Example 22 with VirtualMachine

use of com.microsoft.azure.management.compute.VirtualMachine in project stdlib by petergeneric.

the class AzureVMControlImpl method start.

@Override
public void start(final String id, final Timeout timeout) throws InterruptedException {
    final VirtualMachine vm = getById(id);
    start(vm, timeout);
}
Also used : VirtualMachine(com.microsoft.azure.management.compute.VirtualMachine)

Example 23 with VirtualMachine

use of com.microsoft.azure.management.compute.VirtualMachine in project stdlib by petergeneric.

the class AzureVMControlImpl method restart.

@Override
public void restart(final String id, final Timeout timeout) throws InterruptedException {
    final VirtualMachine vm = getById(id);
    restart(vm, timeout);
}
Also used : VirtualMachine(com.microsoft.azure.management.compute.VirtualMachine)

Example 24 with VirtualMachine

use of com.microsoft.azure.management.compute.VirtualMachine in project stdlib by petergeneric.

the class AzureVMControlImpl method stopAsync.

@Override
public Future<Void> stopAsync(final String id) {
    final VirtualMachine vm = getById(id);
    final String threadName = "Azure Async Call - " + vm.resourceGroupName() + " - " + vm.name();
    ThreadRenameCallableWrap<Void> call = new ThreadRenameCallableWrap<Void>(threadName, new Callable<Void>() {

        @Override
        public Void call() throws Exception {
            stop(vm, Timeout.THIRTY_MINUTES);
            return null;
        }
    });
    return asynchronous.submit(call);
}
Also used : ThreadRenameCallableWrap(com.peterphi.std.threading.ThreadRenameCallableWrap) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) CloudException(com.microsoft.azure.CloudException) VirtualMachine(com.microsoft.azure.management.compute.VirtualMachine)

Example 25 with VirtualMachine

use of com.microsoft.azure.management.compute.VirtualMachine in project stdlib by petergeneric.

the class AzureVMControlImpl method restartAsync.

@Override
public Future<Void> restartAsync(final String id) {
    final VirtualMachine vm = getById(id);
    final String threadName = "Azure Async Call - " + vm.resourceGroupName() + " - " + vm.name();
    ThreadRenameCallableWrap<Void> call = new ThreadRenameCallableWrap<Void>(threadName, new Callable<Void>() {

        @Override
        public Void call() throws Exception {
            restart(vm, Timeout.THIRTY_MINUTES);
            return null;
        }
    });
    return asynchronous.submit(call);
}
Also used : ThreadRenameCallableWrap(com.peterphi.std.threading.ThreadRenameCallableWrap) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) CloudException(com.microsoft.azure.CloudException) VirtualMachine(com.microsoft.azure.management.compute.VirtualMachine)

Aggregations

VirtualMachine (com.microsoft.azure.management.compute.VirtualMachine)68 ArrayList (java.util.ArrayList)21 Region (com.microsoft.azure.management.resources.fluentcore.arm.Region)20 Network (com.microsoft.azure.management.network.Network)17 Date (java.util.Date)12 Disk (com.microsoft.azure.management.compute.Disk)10 PublicIPAddress (com.microsoft.azure.management.network.PublicIPAddress)10 ResourceGroup (com.microsoft.azure.management.resources.ResourceGroup)9 Creatable (com.microsoft.azure.management.resources.fluentcore.model.Creatable)9 Azure (com.microsoft.azure.management.Azure)8 NetworkInterface (com.microsoft.azure.management.network.NetworkInterface)8 IOException (java.io.IOException)8 StopWatch (org.apache.commons.lang3.time.StopWatch)7 VirtualMachineDataDisk (com.microsoft.azure.management.compute.VirtualMachineDataDisk)6 HashMap (java.util.HashMap)6 StorageAccount (com.microsoft.azure.management.storage.StorageAccount)5 JSchException (com.jcraft.jsch.JSchException)4 CloudException (com.microsoft.azure.CloudException)4 DockerHost (com.microsoft.azure.docker.model.DockerHost)4 NetworkSecurityGroup (com.microsoft.azure.management.network.NetworkSecurityGroup)4