Search in sources :

Example 41 with AuthCredentialsServiceState

use of com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState in project photon-model by vmware.

the class AzureLoadBalancerServiceTest method setUpTests.

@Before
public void setUpTests() throws Throwable {
    if (computeHost == null) {
        ResourcePoolState resourcePool = createDefaultResourcePool(this.host);
        endpointState = this.createEndpointState();
        // create a compute host for the Azure
        computeHost = createDefaultComputeHost(this.host, resourcePool.documentSelfLink, endpointState);
    }
    AuthCredentialsServiceState azureVMAuth = new AuthCredentialsServiceState();
    azureVMAuth.userEmail = AZURE_ADMIN_USERNAME;
    azureVMAuth.privateKey = AZURE_ADMIN_PASSWORD;
    azureVMAuth = TestUtils.doPost(host, azureVMAuth, AuthCredentialsServiceState.class, UriUtils.buildUri(host, AuthCredentialsService.FACTORY_LINK));
    ComputeDescription compDesc = buildComputeDescription(host, computeHost, endpointState, azureVMAuth);
    this.rgName = AzureUtils.DEFAULT_GROUP_PREFIX + compDesc.documentCreationTimeMicros / 1000;
    ResourceGroupState rgState = createDefaultResourceGroupState(this.host, this.rgName, computeHost, endpointState, ResourceGroupStateType.AzureResourceGroup);
    networkState = createNetworkState(rgState.documentSelfLink);
    vmStates = new ArrayList<>();
    for (int i = 0; i < poolSize; i++) {
        ComputeState vmState = createDefaultVMResource(getHost(), this.rgName + "VM" + i, computeHost, endpointState, NO_PUBLIC_IP_NIC_SPEC, null, 0, compDesc, this.rgName);
        vmStates.add(vmState);
    }
    subnetState = createSubnetState(this.subnetName);
    if (!this.isMock) {
        this.loadBalancerClient = getAzureSdkClients().getNetworkManagementClientImpl().loadBalancers();
        this.rgOpsClient = getAzureSdkClients().getResourceManagementClientImpl().resourceGroups();
        ResourceGroupInner rg = new ResourceGroupInner();
        rg.withName(this.rgName);
        rg.withLocation(this.regionId);
        this.rgOpsClient.createOrUpdate(this.rgName, rg);
        VirtualNetworkInner vNet = new VirtualNetworkInner();
        AddressSpace addressSpace = new AddressSpace();
        addressSpace.withAddressPrefixes(Collections.singletonList(AZURE_DEFAULT_VPC_CIDR));
        vNet.withAddressSpace(addressSpace);
        vNet.withLocation(this.regionId);
        VirtualNetworksInner vNetClient = getAzureSdkClients().getNetworkManagementClientImpl().virtualNetworks();
        vNetClient.createOrUpdate(this.rgName, this.vNetName, vNet);
        kickOffComputeProvision();
        kickOffSubnetProvision(InstanceRequestType.CREATE, subnetState, TaskStage.FINISHED);
    }
}
Also used : ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) VirtualNetworksInner(com.microsoft.azure.management.network.implementation.VirtualNetworksInner) 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) ComputeDescription(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription) AzureTestUtil.buildComputeDescription(com.vmware.photon.controller.model.adapters.azure.instance.AzureTestUtil.buildComputeDescription) ResourceGroupState(com.vmware.photon.controller.model.resources.ResourceGroupService.ResourceGroupState) AzureTestUtil.createDefaultResourceGroupState(com.vmware.photon.controller.model.adapters.azure.instance.AzureTestUtil.createDefaultResourceGroupState) Before(org.junit.Before)

Example 42 with AuthCredentialsServiceState

use of com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState 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 43 with AuthCredentialsServiceState

use of com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState in project photon-model by vmware.

the class AzureTestUtil method createDefaultAuthCredentials.

public static AuthCredentialsServiceState createDefaultAuthCredentials(VerificationHost host, String clientID, String clientKey, String subscriptionId, String tenantId) throws Throwable {
    AuthCredentialsServiceState auth = new AuthCredentialsServiceState();
    auth.privateKeyId = clientID;
    auth.privateKey = clientKey;
    auth.userLink = subscriptionId;
    auth.customProperties = new HashMap<>();
    auth.customProperties.put(AZURE_TENANT_ID, tenantId);
    auth.documentSelfLink = UUID.randomUUID().toString();
    return TestUtils.doPost(host, auth, AuthCredentialsServiceState.class, UriUtils.buildUri(host, AuthCredentialsService.FACTORY_LINK));
}
Also used : AuthCredentialsServiceState(com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState)

Example 44 with AuthCredentialsServiceState

use of com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState in project photon-model by vmware.

the class EndpointAdapterUtils method configureEndpoint.

private static void configureEndpoint(StatelessService service, EndpointConfigRequest body, BiConsumer<AuthCredentialsServiceState, Retriever> credEnhancer, BiConsumer<ComputeDescription, Retriever> descEnhancer, BiConsumer<ComputeState, Retriever> compEnhancer, BiConsumer<EndpointState, Retriever> endpointEnhancer) {
    TaskManager tm = new TaskManager(service, body.taskReference, body.resourceLink());
    Consumer<Throwable> onFailure = tm::patchTaskToFailure;
    Consumer<Operation> onSuccess = (op) -> {
        EndpointState endpoint = op.getBody(EndpointState.class);
        op.complete();
        AuthCredentialsServiceState authState = new AuthCredentialsServiceState();
        Map<String, String> props = new HashMap<>(body.endpointProperties);
        props.put(MOCK_REQUEST, String.valueOf(body.isMockRequest));
        props.put(ENDPOINT_REFERENCE_URI, body.resourceReference.toString());
        Retriever r = Retriever.of(props);
        try {
            credEnhancer.accept(authState, r);
            ComputeDescription cd = new ComputeDescription();
            descEnhancer.accept(cd, r);
            ComputeState cs = new ComputeState();
            cs.powerState = PowerState.ON;
            compEnhancer.accept(cs, r);
            EndpointState es = new EndpointState();
            es.endpointProperties = new HashMap<>();
            es.regionId = r.get(EndpointConfigRequest.REGION_KEY).orElse(null);
            endpointEnhancer.accept(es, r);
            Stream<Operation> operations = Stream.of(Pair.of(authState, endpoint.authCredentialsLink), Pair.of(cd, endpoint.computeDescriptionLink), Pair.of(cs, endpoint.computeLink), Pair.of(es, endpoint.documentSelfLink)).map((p) -> Operation.createPatch(createInventoryUri(service.getHost(), p.right)).setBody(p.left).setReferer(service.getUri()));
            applyChanges(tm, service, endpoint, operations);
        } catch (Exception e) {
            tm.patchTaskToFailure(e);
        }
    };
    AdapterUtils.getServiceState(service, body.resourceReference, onSuccess, onFailure);
}
Also used : PowerState(com.vmware.photon.controller.model.resources.ComputeService.PowerState) AuthCredentialsServiceState(com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState) HashMap(java.util.HashMap) ServiceEndpointLocator(com.vmware.photon.controller.model.util.ServiceEndpointLocator) Level(java.util.logging.Level) Utils(com.vmware.xenon.common.Utils) EndpointConfigRequest(com.vmware.photon.controller.model.adapterapi.EndpointConfigRequest) Query(com.vmware.xenon.services.common.QueryTask.Query) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) Map(java.util.Map) BiConsumer(java.util.function.BiConsumer) EndpointType(com.vmware.photon.controller.model.constants.PhotonModelConstants.EndpointType) URI(java.net.URI) EndpointState(com.vmware.photon.controller.model.resources.EndpointService.EndpointState) INVENTORY_SERVICE(com.vmware.photon.controller.model.util.ClusterUtil.ServiceTypeCluster.INVENTORY_SERVICE) ServiceErrorResponse(com.vmware.xenon.common.ServiceErrorResponse) ComputeDescription(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription) StatelessService(com.vmware.xenon.common.StatelessService) Operation(com.vmware.xenon.common.Operation) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) PHOTON_MODEL_ADAPTER_ENDPOINT_NOT_UNIQUE_MESSAGE_CODE(com.vmware.photon.controller.model.adapters.util.AdapterConstants.PHOTON_MODEL_ADAPTER_ENDPOINT_NOT_UNIQUE_MESSAGE_CODE) Collectors(java.util.stream.Collectors) ServiceHost(com.vmware.xenon.common.ServiceHost) PHOTON_MODEL_ADAPTER_ENDPOINT_NOT_UNIQUE_MESSAGE(com.vmware.photon.controller.model.adapters.util.AdapterConstants.PHOTON_MODEL_ADAPTER_ENDPOINT_NOT_UNIQUE_MESSAGE) QueryTop(com.vmware.photon.controller.model.query.QueryUtils.QueryTop) Consumer(java.util.function.Consumer) List(java.util.List) RequestType(com.vmware.photon.controller.model.adapterapi.EndpointConfigRequest.RequestType) PhotonModelAdapterConfig(com.vmware.photon.controller.model.adapters.registry.PhotonModelAdaptersRegistryService.PhotonModelAdapterConfig) Stream(java.util.stream.Stream) ClusterUtil(com.vmware.photon.controller.model.util.ClusterUtil) LocalizableValidationException(com.vmware.xenon.common.LocalizableValidationException) DeferredResult(com.vmware.xenon.common.DeferredResult) UriUtils.buildUri(com.vmware.xenon.common.UriUtils.buildUri) Optional(java.util.Optional) PhotonModelAdaptersRegistryService(com.vmware.photon.controller.model.adapters.registry.PhotonModelAdaptersRegistryService) Builder(com.vmware.xenon.services.common.QueryTask.Query.Builder) Collections(java.util.Collections) OperationJoin(com.vmware.xenon.common.OperationJoin) PhotonModelUriUtils.createInventoryUri(com.vmware.photon.controller.model.util.PhotonModelUriUtils.createInventoryUri) ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) ComputeDescription(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription) HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Operation(com.vmware.xenon.common.Operation) LocalizableValidationException(com.vmware.xenon.common.LocalizableValidationException) EndpointState(com.vmware.photon.controller.model.resources.EndpointService.EndpointState) AuthCredentialsServiceState(com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState) Stream(java.util.stream.Stream) HashMap(java.util.HashMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 45 with AuthCredentialsServiceState

use of com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState in project photon-model by vmware.

the class EndpointAdapterUtils method getAuthLinks.

private static DeferredResult<List<String>> getAuthLinks(ServiceHost host, Query authQuery, List<String> queryTaskTenantLinks) {
    Query.Builder authQueryBuilder = Builder.create().addKindFieldClause(AuthCredentialsServiceState.class);
    if (authQuery != null) {
        authQueryBuilder.addClause(authQuery);
    }
    QueryTop<AuthCredentialsServiceState> queryAuth = new QueryTop<>(host, authQueryBuilder.build(), AuthCredentialsServiceState.class, queryTaskTenantLinks).setQueryTaskTenantLinks(queryTaskTenantLinks);
    queryAuth.setClusterType(INVENTORY_SERVICE);
    return queryAuth.collectLinks(Collectors.toList());
}
Also used : AuthCredentialsServiceState(com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState) Query(com.vmware.xenon.services.common.QueryTask.Query) Builder(com.vmware.xenon.services.common.QueryTask.Query.Builder)

Aggregations

AuthCredentialsServiceState (com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState)98 Operation (com.vmware.xenon.common.Operation)33 Before (org.junit.Before)28 ResourcePoolState (com.vmware.photon.controller.model.resources.ResourcePoolService.ResourcePoolState)25 Test (org.junit.Test)22 ArrayList (java.util.ArrayList)19 UriUtils (com.vmware.xenon.common.UriUtils)18 URI (java.net.URI)18 List (java.util.List)18 HashMap (java.util.HashMap)17 CompletionException (java.util.concurrent.CompletionException)16 ComputeState (com.vmware.photon.controller.model.resources.ComputeService.ComputeState)15 Utils (com.vmware.xenon.common.Utils)15 ComputeDescription (com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription)14 StatelessService (com.vmware.xenon.common.StatelessService)13 TimeUnit (java.util.concurrent.TimeUnit)13 Collections (java.util.Collections)12 AmazonEC2AsyncClient (com.amazonaws.services.ec2.AmazonEC2AsyncClient)11 SecurityGroupState (com.vmware.photon.controller.model.resources.SecurityGroupService.SecurityGroupState)11 EndpointState (com.vmware.photon.controller.model.resources.EndpointService.EndpointState)10