Search in sources :

Example 91 with AuthCredentialsServiceState

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

the class TestProvisionAWSSecurityGroup method testProvisionAWSSecurityGroup.

@Test
public void testProvisionAWSSecurityGroup() throws Throwable {
    // create credentials
    Operation authResponse = new Operation();
    TestUtils.postCredentials(this.host, authResponse, this.privateKey, this.privateKeyId);
    AuthCredentialsServiceState creds = authResponse.getBody(AuthCredentialsServiceState.class);
    // create resource pool
    Operation poolResponse = new Operation();
    TestUtils.postResourcePool(this.host, poolResponse);
    ResourcePoolState pool = poolResponse.getBody(ResourcePoolState.class);
    // create sg service
    Operation securityGroupResponse = new Operation();
    SecurityGroupState initialSecurityGroupState = buildSecurityGroupState(creds, pool);
    TestUtils.postSecurityGroup(this.host, initialSecurityGroupState, securityGroupResponse);
    SecurityGroupState securityGroupState = securityGroupResponse.getBody(SecurityGroupState.class);
    // set up security group task state
    ProvisionSecurityGroupTaskState task = new ProvisionSecurityGroupTaskState();
    task.requestType = SecurityGroupInstanceRequest.InstanceRequestType.CREATE;
    task.securityGroupDescriptionLinks = Stream.of(securityGroupState.documentSelfLink).collect(Collectors.toSet());
    task.customProperties = new HashMap<>();
    task.customProperties.put(NETWORK_STATE_ID_PROP_NAME, this.vpcId);
    Operation provision = new Operation();
    provisionSecurityGroup(task, provision);
    ProvisionSecurityGroupTaskState ps = provision.getBody(ProvisionSecurityGroupTaskState.class);
    waitForTaskCompletion(this.host, UriUtils.buildUri(this.host, ps.documentSelfLink));
    validateAWSArtifacts(securityGroupState.documentSelfLink, creds);
    // reuse previous task, but switch to a delete
    task.requestType = SecurityGroupInstanceRequest.InstanceRequestType.DELETE;
    Operation remove = new Operation();
    provisionSecurityGroup(task, remove);
    ProvisionSecurityGroupTaskState removeTask = remove.getBody(ProvisionSecurityGroupTaskState.class);
    waitForTaskCompletion(this.host, UriUtils.buildUri(this.host, removeTask.documentSelfLink));
    // verify security group state is gone
    try {
        getSecurityGroupState(securityGroupState.documentSelfLink);
    } catch (Exception ex) {
        assertTrue(ex instanceof ServiceNotFoundException);
    }
}
Also used : AuthCredentialsServiceState(com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState) ResourcePoolState(com.vmware.photon.controller.model.resources.ResourcePoolService.ResourcePoolState) ProvisionSecurityGroupTaskState(com.vmware.photon.controller.model.tasks.ProvisionSecurityGroupTaskService.ProvisionSecurityGroupTaskState) SecurityGroupState(com.vmware.photon.controller.model.resources.SecurityGroupService.SecurityGroupState) ServiceNotFoundException(com.vmware.xenon.common.ServiceHost.ServiceNotFoundException) Operation(com.vmware.xenon.common.Operation) TimeoutException(java.util.concurrent.TimeoutException) ServiceNotFoundException(com.vmware.xenon.common.ServiceHost.ServiceNotFoundException) CompletionException(java.util.concurrent.CompletionException) BaseModelTest(com.vmware.photon.controller.model.helpers.BaseModelTest) Test(org.junit.Test)

Example 92 with AuthCredentialsServiceState

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

the class TestUtils method postCredentials.

public static void postCredentials(VerificationHost host, Operation response, String privateKey, String privateKeyId) throws Throwable {
    AuthCredentialsServiceState creds = new AuthCredentialsServiceState();
    creds.privateKey = privateKey;
    creds.privateKeyId = privateKeyId;
    URI authFactory = UriUtils.buildFactoryUri(host, AuthCredentialsService.class);
    host.testStart(1);
    Operation startPost = Operation.createPost(authFactory).setBody(creds).setCompletion((o, e) -> {
        if (e != null) {
            host.failIteration(e);
            return;
        }
        response.setBody(o.getBody(AuthCredentialsServiceState.class));
        host.completeIteration();
    });
    host.send(startPost);
    host.testWait();
}
Also used : AuthCredentialsServiceState(com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState) Operation(com.vmware.xenon.common.Operation) URI(java.net.URI)

Example 93 with AuthCredentialsServiceState

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

the class TestAWSEnumerationAtScale method initResourcePoolAndComputeHost.

/**
 * Creates the state associated with the resource pool, compute host and the VM to be created.
 * @throws Throwable
 */
public void initResourcePoolAndComputeHost() throws Throwable {
    // Create a resource pool where the VM will be housed
    ResourcePoolState resourcePool = createAWSResourcePool(this.host);
    AuthCredentialsServiceState auth = createAWSAuthentication(this.host, this.accessKey, this.secretKey);
    this.endpointState = TestAWSSetupUtils.createAWSEndpointState(this.host, auth.documentSelfLink, resourcePool.documentSelfLink);
    // create a compute host for the AWS EC2 VM
    this.computeHost = createAWSComputeHost(this.host, this.endpointState, zoneId, regionId, this.isAwsClientMock, this.awsMockEndpointReference, null);
}
Also used : ResourcePoolState(com.vmware.photon.controller.model.resources.ResourcePoolService.ResourcePoolState) AuthCredentialsServiceState(com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState)

Example 94 with AuthCredentialsServiceState

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

the class TestAWSEnumerationTask method testGetAvailableRegions.

@Test
public void testGetAvailableRegions() {
    URI uri = UriUtils.buildUri(ServiceHost.LOCAL_HOST, host.getPort(), UriPaths.AdapterTypePath.REGION_ENUMERATION_ADAPTER.adapterLink(PhotonModelConstants.EndpointType.aws.toString().toLowerCase()), null);
    Operation post = Operation.createPost(uri);
    post.setBody(new AuthCredentialsServiceState());
    Operation operation = host.getTestRequestSender().sendAndWait(post);
    RegionEnumerationResponse result = operation.getBody(RegionEnumerationResponse.class);
    assertEquals(Regions.values().length, result.regions.size());
}
Also used : AuthCredentialsServiceState(com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState) RegionEnumerationResponse(com.vmware.photon.controller.model.adapterapi.RegionEnumerationResponse) Operation(com.vmware.xenon.common.Operation) URI(java.net.URI) Test(org.junit.Test)

Example 95 with AuthCredentialsServiceState

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

the class AzureSubscriptionEndpointCreationService method createAuthCredentialsState.

private AuthCredentialsServiceState createAuthCredentialsState(EndpointState azureEaEndpoint, AzureSubscriptionEndpointCreationRequest request) {
    AuthCredentialsServiceState authCredState = new AuthCredentialsServiceState();
    authCredState.userLink = request.subscriptionId;
    authCredState.tenantLinks = azureEaEndpoint.tenantLinks;
    return authCredState;
}
Also used : AuthCredentialsServiceState(com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState)

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