Search in sources :

Example 1 with ResourceManagementClientImpl

use of com.microsoft.azure.management.resources.implementation.ResourceManagementClientImpl in project photon-model by vmware.

the class AzureInstanceService method registerSubscription.

private void registerSubscription(AzureInstanceContext ctx, String namespace) {
    ResourceManagementClientImpl client = getResourceManagementClientImpl(ctx);
    client.providers().registerAsync(namespace, new AzureAsyncCallback<ProviderInner>() {

        @Override
        public void onError(Throwable e) {
            handleError(ctx, e);
        }

        @Override
        public void onSuccess(ProviderInner result) {
            String registrationState = result.registrationState();
            if (!PROVIDER_REGISTRED_STATE.equalsIgnoreCase(registrationState)) {
                logInfo(() -> String.format("%s namespace registration in %s state", namespace, registrationState));
                long retryExpiration = Utils.getNowMicrosUtc() + DEFAULT_EXPIRATION_INTERVAL_MICROS;
                getSubscriptionState(ctx, namespace, retryExpiration);
                return;
            }
            logFine(() -> String.format("Successfully registered namespace [%s]", result.namespace()));
            handleAllocation(ctx);
        }
    });
}
Also used : ProviderInner(com.microsoft.azure.management.resources.implementation.ProviderInner) ResourceManagementClientImpl(com.microsoft.azure.management.resources.implementation.ResourceManagementClientImpl)

Example 2 with ResourceManagementClientImpl

use of com.microsoft.azure.management.resources.implementation.ResourceManagementClientImpl in project photon-model by vmware.

the class AzureInstanceService method getSubscriptionState.

private void getSubscriptionState(AzureInstanceContext ctx, String namespace, long retryExpiration) {
    if (Utils.getNowMicrosUtc() > retryExpiration) {
        String msg = String.format("Subscription for %s namespace did not reach %s state", namespace, PROVIDER_REGISTRED_STATE);
        handleError(ctx, new RuntimeException(msg));
        return;
    }
    ResourceManagementClientImpl client = getResourceManagementClientImpl(ctx);
    getHost().schedule(() -> client.providers().getAsync(namespace, new AzureAsyncCallback<ProviderInner>() {

        @Override
        public void onError(Throwable e) {
            handleError(ctx, e);
        }

        @Override
        public void onSuccess(ProviderInner result) {
            String registrationState = result.registrationState();
            if (!PROVIDER_REGISTRED_STATE.equalsIgnoreCase(registrationState)) {
                logInfo(() -> String.format("%s namespace registration in %s state", namespace, registrationState));
                getSubscriptionState(ctx, namespace, retryExpiration);
                return;
            }
            logFine(() -> String.format("Successfully registered namespace [%s]", result.namespace()));
            handleAllocation(ctx);
        }
    }), RETRY_INTERVAL_SECONDS, TimeUnit.SECONDS);
}
Also used : AzureAsyncCallback(com.vmware.photon.controller.model.adapters.azure.AzureAsyncCallback) ProviderInner(com.microsoft.azure.management.resources.implementation.ProviderInner) ResourceManagementClientImpl(com.microsoft.azure.management.resources.implementation.ResourceManagementClientImpl)

Example 3 with ResourceManagementClientImpl

use of com.microsoft.azure.management.resources.implementation.ResourceManagementClientImpl 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 4 with ResourceManagementClientImpl

use of com.microsoft.azure.management.resources.implementation.ResourceManagementClientImpl in project photon-model by vmware.

the class AzureSubnetTaskServiceTest method setUp.

@Override
@Before
public void setUp() throws Throwable {
    CommandLineArgumentParser.parseFromProperties(this);
    if (computeHost == null) {
        PhotonModelServices.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);
        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);
        NetworkManagementClientImpl networkManagementClient = new NetworkManagementClientImpl(credentials).withSubscriptionId(this.subscriptionId);
        ResourceManagementClientImpl resourceManagementClient = new ResourceManagementClientImpl(credentials).withSubscriptionId(this.subscriptionId);
        this.vNetClient = networkManagementClient.virtualNetworks();
        this.rgOpsClient = resourceManagementClient.resourceGroups();
        this.subnetsClient = networkManagementClient.subnets();
        ResourceGroupInner rg = new ResourceGroupInner();
        rg.withName(this.rgName);
        rg.withLocation(this.regionId);
        this.rgOpsClient.createOrUpdate(this.rgName, rg);
        VirtualNetworkInner vNet = new VirtualNetworkInner();
        // Azure's custom serializers don't handle well collections constructed with
        // Collections.singletonList(), so initialize an ArrayList
        AddressSpace addressSpace = new AddressSpace();
        List<String> cidrs = new ArrayList<>();
        cidrs.add(AZURE_DEFAULT_VPC_CIDR);
        addressSpace.withAddressPrefixes(cidrs);
        vNet.withAddressSpace(addressSpace);
        vNet.withLocation(this.regionId);
        this.vNetClient.createOrUpdate(this.rgName, this.vNetName, vNet);
    }
    ResourceGroupState rgState = createDefaultResourceGroupState(this.host, this.rgName, computeHost, endpointState, ResourceGroupStateType.AzureResourceGroup);
    this.networkState = createNetworkState(rgState.documentSelfLink);
}
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) VirtualNetworkInner(com.microsoft.azure.management.network.implementation.VirtualNetworkInner) ResourceGroupInner(com.microsoft.azure.management.resources.implementation.ResourceGroupInner) AddressSpace(com.microsoft.azure.management.network.AddressSpace) ResourceGroupState(com.vmware.photon.controller.model.resources.ResourceGroupService.ResourceGroupState) AzureTestUtil.createDefaultResourceGroupState(com.vmware.photon.controller.model.adapters.azure.instance.AzureTestUtil.createDefaultResourceGroupState) ArrayList(java.util.ArrayList) ApplicationTokenCredentials(com.microsoft.azure.credentials.ApplicationTokenCredentials) ResourceManagementClientImpl(com.microsoft.azure.management.resources.implementation.ResourceManagementClientImpl) Before(org.junit.Before)

Example 5 with ResourceManagementClientImpl

use of com.microsoft.azure.management.resources.implementation.ResourceManagementClientImpl in project photon-model by vmware.

the class TestAzureLongRunningEnumeration method setUp.

@Override
@Before
public void setUp() throws Exception {
    for (int i = 0; i < numOfVMsToTest; i++) {
        String azureName = generateName(azureVMNamePrefix);
        azureVMNames.add(azureName);
        nicSpecs.add(initializeNicSpecs(azureName, false, true, false));
    }
    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);
            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(this.timeoutSeconds);
            // 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.waitForServiceAvailable(PhotonModelServices.LINKS);
        this.host.waitForServiceAvailable(PhotonModelTaskServices.LINKS);
        this.nodeStatsUri = UriUtils.buildUri(this.host.getUri(), ServiceUriPaths.CORE_MANAGEMENT);
        this.maxMemoryInMb = this.host.getState().systemInfo.maxMemoryByteCount / BYTES_TO_MB;
        internalTagResourcesMap.put(NetworkState.class, NETWORK_TAG_TYPE_VALUE);
        internalTagResourcesMap.put(SubnetState.class, SUBNET_TAG_TYPE_VALUE);
        internalTagResourcesMap.put(NetworkInterfaceState.class, NETWORK_INTERFACE_TAG_TYPE_VALUE);
        if (!this.isMock) {
            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.storageManagementClient = new StorageManagementClientImpl(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) StorageManagementClientImpl(com.microsoft.azure.management.storage.implementation.StorageManagementClientImpl) ComputeManagementClientImpl(com.microsoft.azure.management.compute.implementation.ComputeManagementClientImpl) ApplicationTokenCredentials(com.microsoft.azure.credentials.ApplicationTokenCredentials) AzureTestUtil.randomString(com.vmware.photon.controller.model.adapters.azure.instance.AzureTestUtil.randomString) ResourceManagementClientImpl(com.microsoft.azure.management.resources.implementation.ResourceManagementClientImpl) Before(org.junit.Before)

Aggregations

ResourceManagementClientImpl (com.microsoft.azure.management.resources.implementation.ResourceManagementClientImpl)5 ApplicationTokenCredentials (com.microsoft.azure.credentials.ApplicationTokenCredentials)3 NetworkManagementClientImpl (com.microsoft.azure.management.network.implementation.NetworkManagementClientImpl)3 ResourcePoolState (com.vmware.photon.controller.model.resources.ResourcePoolService.ResourcePoolState)3 AuthCredentialsServiceState (com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState)3 Before (org.junit.Before)3 ComputeManagementClientImpl (com.microsoft.azure.management.compute.implementation.ComputeManagementClientImpl)2 ProviderInner (com.microsoft.azure.management.resources.implementation.ProviderInner)2 AzureEnvironment (com.microsoft.azure.AzureEnvironment)1 AddressSpace (com.microsoft.azure.management.network.AddressSpace)1 VirtualNetworkInner (com.microsoft.azure.management.network.implementation.VirtualNetworkInner)1 ResourceGroupInner (com.microsoft.azure.management.resources.implementation.ResourceGroupInner)1 StorageManagementClientImpl (com.microsoft.azure.management.storage.implementation.StorageManagementClientImpl)1 AzureAsyncCallback (com.vmware.photon.controller.model.adapters.azure.AzureAsyncCallback)1 AzureTestUtil.createDefaultResourceGroupState (com.vmware.photon.controller.model.adapters.azure.instance.AzureTestUtil.createDefaultResourceGroupState)1 AzureTestUtil.randomString (com.vmware.photon.controller.model.adapters.azure.instance.AzureTestUtil.randomString)1 ResourceGroupState (com.vmware.photon.controller.model.resources.ResourceGroupService.ResourceGroupState)1 ArrayList (java.util.ArrayList)1