Search in sources :

Example 1 with ComputeManagementClientImpl

use of com.microsoft.azure.management.compute.implementation.ComputeManagementClientImpl in project photon-model by vmware.

the class AzurePowerServiceTest method setUp.

@Before
public void setUp() throws Exception {
    try {
        /*
             * Init Class-specific (shared between test runs) vars.
             *
             * NOTE: Ultimately this should go to @BeforeClass, BUT BasicReusableHostTestCase.HOST
             * is not accessible.
             */
        if (computeHost == null) {
            PhotonModelServices.startServices(this.host);
            PhotonModelMetricServices.startServices(this.host);
            PhotonModelAdaptersRegistryAdapters.startServices(this.host);
            PhotonModelTaskServices.startServices(this.host);
            AzureAdaptersTestUtils.startServicesSynchronouslyAzure(this.host);
            this.host.waitForServiceAvailable(PhotonModelServices.LINKS);
            this.host.waitForServiceAvailable(PhotonModelTaskServices.LINKS);
            // TODO: VSYM-992 - improve test/fix arbitrary timeout
            this.host.setTimeoutSeconds(1200);
            // Create a resource pool where the VM will be housed
            ResourcePoolState resourcePool = createDefaultResourcePool(this.host);
            AuthCredentialsServiceState authCredentials = createDefaultAuthCredentials(this.host, this.clientID, this.clientKey, this.subscriptionId, this.tenantId);
            endpointState = createDefaultEndpointState(this.host, authCredentials.documentSelfLink);
            // create a compute host for the Azure
            computeHost = createDefaultComputeHost(this.host, resourcePool.documentSelfLink, endpointState);
        }
        if (!this.isMock) {
            ApplicationTokenCredentials credentials = new ApplicationTokenCredentials(this.clientID, this.tenantId, this.clientKey, AzureEnvironment.AZURE);
            this.computeManagementClient = new ComputeManagementClientImpl(credentials).withSubscriptionId(this.subscriptionId);
        }
    } catch (Throwable e) {
        throw new Exception(e);
    }
}
Also used : ResourcePoolState(com.vmware.photon.controller.model.resources.ResourcePoolService.ResourcePoolState) AuthCredentialsServiceState(com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState) ComputeManagementClientImpl(com.microsoft.azure.management.compute.implementation.ComputeManagementClientImpl) ApplicationTokenCredentials(com.microsoft.azure.credentials.ApplicationTokenCredentials) Before(org.junit.Before)

Example 2 with ComputeManagementClientImpl

use of com.microsoft.azure.management.compute.implementation.ComputeManagementClientImpl in project photon-model by vmware.

the class TestAzureEnumerationTask method setUp.

@Override
@Before
public void setUp() throws Exception {
    try {
        /*
             * Init Class-specific (shared between test runs) vars.
             *
             * NOTE: Ultimately this should go to @BeforeClass, BUT BasicReusableHostTestCase.HOST
             * is not accessible.
             */
        if (computeHost == null) {
            PhotonModelServices.startServices(this.host);
            PhotonModelMetricServices.startServices(this.host);
            PhotonModelTaskServices.startServices(this.host);
            PhotonModelAdaptersRegistryAdapters.startServices(this.host);
            AzureAdaptersTestUtils.startServicesSynchronouslyAzure(this.host);
            this.host.waitForServiceAvailable(PhotonModelServices.LINKS);
            this.host.waitForServiceAvailable(PhotonModelTaskServices.LINKS);
            // TODO: VSYM-992 - improve test/fix arbitrary timeout
            this.host.setTimeoutSeconds(600);
            // Create a resource pool where the VMs will be housed
            ResourcePoolState resourcePool = createDefaultResourcePool(this.host);
            AuthCredentialsServiceState authCredentials = createDefaultAuthCredentials(this.host, this.clientID, this.clientKey, this.subscriptionId, this.tenantId);
            endpointState = createDefaultEndpointState(this.host, authCredentials.documentSelfLink);
            // create a compute host for the Azure
            computeHost = createDefaultComputeHost(this.host, resourcePool.documentSelfLink, endpointState);
            endpointState.computeHostLink = computeHost.documentSelfLink;
            this.host.waitForResponse(Operation.createPatch(this.host, endpointState.documentSelfLink).setBody(endpointState));
        }
        azureVMName = azureVMName == null ? generateName(azureVMNamePrefix) : azureVMName;
        this.host.waitForServiceAvailable(PhotonModelServices.LINKS);
        this.host.waitForServiceAvailable(PhotonModelTaskServices.LINKS);
        AzureUtils.setAzureClientMock(this.isAzureClientMock);
        AzureUtils.setAzureMockHost(this.azureMockEndpointReference);
        if (!this.isMock) {
            if (AzureUtils.isAzureClientMock()) {
                AzureEnvironment azureEnv = AzureEnvironment.AZURE;
                azureEnv.endpoints().put(AzureEnvironment.Endpoint.ACTIVE_DIRECTORY.toString(), AzureUtils.getAzureBaseUri());
                ApplicationTokenCredentials credentials = new ApplicationTokenCredentials(this.clientID, this.tenantId, this.clientKey, azureEnv);
                this.computeManagementClient = new ComputeManagementClientImpl(AzureUtils.getAzureBaseUri(), credentials).withSubscriptionId(this.subscriptionId);
                this.resourceManagementClient = new ResourceManagementClientImpl(AzureUtils.getAzureBaseUri(), credentials).withSubscriptionId(this.subscriptionId);
                this.networkManagementClient = new NetworkManagementClientImpl(AzureUtils.getAzureBaseUri(), credentials).withSubscriptionId(this.subscriptionId);
            } else {
                ApplicationTokenCredentials credentials = new ApplicationTokenCredentials(this.clientID, this.tenantId, this.clientKey, AzureEnvironment.AZURE);
                this.computeManagementClient = new ComputeManagementClientImpl(credentials).withSubscriptionId(this.subscriptionId);
                ;
                this.resourceManagementClient = new ResourceManagementClientImpl(credentials).withSubscriptionId(this.subscriptionId);
                ;
                this.networkManagementClient = new NetworkManagementClientImpl(credentials).withSubscriptionId(this.subscriptionId);
                ;
            }
        }
    } catch (Throwable e) {
        throw new Exception(e);
    }
}
Also used : NetworkManagementClientImpl(com.microsoft.azure.management.network.implementation.NetworkManagementClientImpl) ResourcePoolState(com.vmware.photon.controller.model.resources.ResourcePoolService.ResourcePoolState) AuthCredentialsServiceState(com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState) ComputeManagementClientImpl(com.microsoft.azure.management.compute.implementation.ComputeManagementClientImpl) AzureEnvironment(com.microsoft.azure.AzureEnvironment) ApplicationTokenCredentials(com.microsoft.azure.credentials.ApplicationTokenCredentials) ResourceManagementClientImpl(com.microsoft.azure.management.resources.implementation.ResourceManagementClientImpl) Before(org.junit.Before)

Example 3 with ComputeManagementClientImpl

use of com.microsoft.azure.management.compute.implementation.ComputeManagementClientImpl in project photon-model by vmware.

the class AzureLifecycleOperationServiceTest method setUp.

@Before
public void setUp() throws Exception {
    try {
        /*
             * Init Class-specific (shared between test runs) vars.
             *
             * NOTE: Ultimately this should go to @BeforeClass, BUT BasicReusableHostTestCase.HOST
             * is not accessible.
             */
        if (computeHost == null) {
            PhotonModelServices.startServices(this.host);
            PhotonModelAdaptersRegistryAdapters.startServices(this.host);
            PhotonModelMetricServices.startServices(this.host);
            PhotonModelTaskServices.startServices(this.host);
            AzureAdaptersTestUtils.startServicesSynchronouslyAzure(this.host);
            this.host.waitForServiceAvailable(PhotonModelServices.LINKS);
            this.host.waitForServiceAvailable(PhotonModelTaskServices.LINKS);
            // TODO: VSYM-992 - improve test/fix arbitrary timeout
            this.host.setTimeoutSeconds(1200);
            // Create a resource pool where the VM will be housed
            ResourcePoolState resourcePool = createDefaultResourcePool(this.host);
            AuthCredentialsServiceState authCredentials = createDefaultAuthCredentials(this.host, this.clientID, this.clientKey, this.subscriptionId, this.tenantId);
            endpointState = createDefaultEndpointState(this.host, authCredentials.documentSelfLink);
            // create a compute host for the Azure
            computeHost = createDefaultComputeHost(this.host, resourcePool.documentSelfLink, endpointState);
        }
        if (!this.isMock) {
            ApplicationTokenCredentials credentials = new ApplicationTokenCredentials(this.clientID, this.tenantId, this.clientKey, AzureEnvironment.AZURE);
            this.computeManagementClient = new ComputeManagementClientImpl(credentials).withSubscriptionId(this.subscriptionId);
        }
    } catch (Throwable e) {
        throw new Exception(e);
    }
}
Also used : ResourcePoolState(com.vmware.photon.controller.model.resources.ResourcePoolService.ResourcePoolState) AuthCredentialsServiceState(com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState) ComputeManagementClientImpl(com.microsoft.azure.management.compute.implementation.ComputeManagementClientImpl) ApplicationTokenCredentials(com.microsoft.azure.credentials.ApplicationTokenCredentials) Before(org.junit.Before)

Example 4 with ComputeManagementClientImpl

use of com.microsoft.azure.management.compute.implementation.ComputeManagementClientImpl in project photon-model by vmware.

the class AzureInstanceService method deleteVirtualMachine.

private DeferredResult<AzureInstanceContext> deleteVirtualMachine(AzureInstanceContext ctx) {
    String msg = "Deleting virtual machine [" + ctx.vmName + "]";
    ComputeManagementClientImpl computeManager = getComputeManagementClientImpl(ctx);
    AzureDeferredResultServiceCallback<OperationStatusResponseInner> deleteVirtualMachineCallback = new AzureDeferredResultServiceCallback<OperationStatusResponseInner>(this, msg) {

        @Override
        protected DeferredResult<OperationStatusResponseInner> consumeSuccess(OperationStatusResponseInner result) {
            logInfo("Successfully deleted VM: " + ctx.vmName);
            return DeferredResult.completed(result);
        }
    };
    computeManager.virtualMachines().deleteAsync(ctx.resourceGroupName, ctx.vmName, deleteVirtualMachineCallback);
    return deleteVirtualMachineCallback.toDeferredResult().thenApply(result -> ctx);
}
Also used : OperationStatusResponseInner(com.microsoft.azure.management.compute.implementation.OperationStatusResponseInner) AzureDeferredResultServiceCallback(com.vmware.photon.controller.model.adapters.azure.utils.AzureDeferredResultServiceCallback) ComputeManagementClientImpl(com.microsoft.azure.management.compute.implementation.ComputeManagementClientImpl)

Example 5 with ComputeManagementClientImpl

use of com.microsoft.azure.management.compute.implementation.ComputeManagementClientImpl in project photon-model by vmware.

the class AzureInstanceService method getAvailabilitySets.

private DeferredResult<AzureInstanceContext> getAvailabilitySets(AzureInstanceContext ctx) {
    String msg = "Getting availability sets. ResourceGroup [" + ctx.resourceGroupName + "]";
    ComputeManagementClientImpl computeManager = getComputeManagementClientImpl(ctx);
    AzureDeferredResultServiceCallbackWithRetry<List<AvailabilitySetInner>> getAvailabilitySetsCallback = new AzureDeferredResultServiceCallbackWithRetry<List<AvailabilitySetInner>>(this, msg) {

        @Override
        protected DeferredResult<List<AvailabilitySetInner>> consumeSuccess(List<AvailabilitySetInner> result) {
            ctx.availabilitySetInners = result;
            return DeferredResult.completed(result);
        }

        @Override
        protected Runnable retryServiceCall(ServiceCallback<List<AvailabilitySetInner>> retryCallback) {
            return () -> computeManager.availabilitySets().listByResourceGroupAsync(ctx.resourceGroupName, retryCallback);
        }
    };
    computeManager.availabilitySets().listByResourceGroupAsync(ctx.resourceGroupName, getAvailabilitySetsCallback);
    return getAvailabilitySetsCallback.toDeferredResult().thenApply(result -> ctx);
}
Also used : ServiceCallback(com.microsoft.rest.ServiceCallback) AzureDeferredResultServiceCallback(com.vmware.photon.controller.model.adapters.azure.utils.AzureDeferredResultServiceCallback) ComputeManagementClientImpl(com.microsoft.azure.management.compute.implementation.ComputeManagementClientImpl) ArrayList(java.util.ArrayList) List(java.util.List) AvailabilitySetInner(com.microsoft.azure.management.compute.implementation.AvailabilitySetInner) AzureDeferredResultServiceCallbackWithRetry(com.vmware.photon.controller.model.adapters.azure.utils.AzureDeferredResultServiceCallbackWithRetry)

Aggregations

ComputeManagementClientImpl (com.microsoft.azure.management.compute.implementation.ComputeManagementClientImpl)6 ApplicationTokenCredentials (com.microsoft.azure.credentials.ApplicationTokenCredentials)4 ResourcePoolState (com.vmware.photon.controller.model.resources.ResourcePoolService.ResourcePoolState)4 AuthCredentialsServiceState (com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState)4 Before (org.junit.Before)4 NetworkManagementClientImpl (com.microsoft.azure.management.network.implementation.NetworkManagementClientImpl)2 ResourceManagementClientImpl (com.microsoft.azure.management.resources.implementation.ResourceManagementClientImpl)2 AzureDeferredResultServiceCallback (com.vmware.photon.controller.model.adapters.azure.utils.AzureDeferredResultServiceCallback)2 AzureEnvironment (com.microsoft.azure.AzureEnvironment)1 AvailabilitySetInner (com.microsoft.azure.management.compute.implementation.AvailabilitySetInner)1 OperationStatusResponseInner (com.microsoft.azure.management.compute.implementation.OperationStatusResponseInner)1 StorageManagementClientImpl (com.microsoft.azure.management.storage.implementation.StorageManagementClientImpl)1 ServiceCallback (com.microsoft.rest.ServiceCallback)1 AzureTestUtil.randomString (com.vmware.photon.controller.model.adapters.azure.instance.AzureTestUtil.randomString)1 AzureDeferredResultServiceCallbackWithRetry (com.vmware.photon.controller.model.adapters.azure.utils.AzureDeferredResultServiceCallbackWithRetry)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1