Search in sources :

Example 1 with ProvisionNetworkTaskState

use of com.vmware.photon.controller.model.tasks.ProvisionNetworkTaskService.ProvisionNetworkTaskState in project photon-model by vmware.

the class TestProvisionAWSNetwork method provisionNetwork.

private void provisionNetwork(ProvisionNetworkTaskState ps, Operation response) throws Throwable {
    this.host.testStart(1);
    Operation startPost = Operation.createPost(this.provisionNetworkFactory).setBody(ps).setCompletion((o, e) -> {
        if (e != null) {
            this.host.failIteration(e);
            return;
        }
        response.setBody(o.getBody(ProvisionNetworkTaskState.class));
        this.host.completeIteration();
    });
    this.host.send(startPost);
    this.host.testWait();
}
Also used : ProvisionNetworkTaskState(com.vmware.photon.controller.model.tasks.ProvisionNetworkTaskService.ProvisionNetworkTaskState) Operation(com.vmware.xenon.common.Operation)

Example 2 with ProvisionNetworkTaskState

use of com.vmware.photon.controller.model.tasks.ProvisionNetworkTaskService.ProvisionNetworkTaskState in project photon-model by vmware.

the class TestProvisionAWSNetwork method testProvisionAWSNetwork.

@Test
public void testProvisionAWSNetwork() throws Throwable {
    // first create network service
    Operation response = new Operation();
    // create credentials
    Operation credsResponse = new Operation();
    TestUtils.postCredentials(this.host, credsResponse, this.secretKey, this.accessKey);
    AuthCredentialsServiceState creds = credsResponse.getBody(AuthCredentialsServiceState.class);
    // create resource pool
    Operation poolResponse = new Operation();
    TestUtils.postResourcePool(this.host, poolResponse);
    ResourcePoolState pool = poolResponse.getBody(ResourcePoolState.class);
    NetworkState initialState = TestUtils.buildNetworkState(this.host);
    initialState.authCredentialsLink = creds.documentSelfLink;
    initialState.resourcePoolLink = pool.documentSelfLink;
    initialState.regionId = regionId;
    initialState.instanceAdapterReference = UriUtils.buildUri(ServiceHost.LOCAL_HOST, this.host.getPort(), AWSUriPaths.AWS_NETWORK_ADAPTER, null);
    TestUtils.postNetwork(this.host, initialState, response);
    NetworkState networkState = response.getBody(NetworkState.class);
    // set up network task state
    ProvisionNetworkTaskState task = new ProvisionNetworkTaskState();
    task.requestType = NetworkInstanceRequest.InstanceRequestType.CREATE;
    task.networkDescriptionLink = networkState.documentSelfLink;
    Operation provision = new Operation();
    provisionNetwork(task, provision);
    ProvisionNetworkTaskState ps = provision.getBody(ProvisionNetworkTaskState.class);
    waitForTaskCompletion(this.host, UriUtils.buildUri(this.host, ps.documentSelfLink));
    validateAWSArtifacts(networkState.documentSelfLink, creds);
    task.requestType = NetworkInstanceRequest.InstanceRequestType.DELETE;
    Operation remove = new Operation();
    provisionNetwork(task, remove);
    ProvisionNetworkTaskState removeTask = remove.getBody(ProvisionNetworkTaskState.class);
    waitForTaskCompletion(this.host, UriUtils.buildUri(this.host, removeTask.documentSelfLink));
    // verify properties have been set to no-value
    NetworkState removedNetwork = getNetworkState(networkState.documentSelfLink);
    assertTrue(removedNetwork.customProperties.get(AWS_VPC_ID).equalsIgnoreCase(AWSUtils.NO_VALUE));
    assertTrue(removedNetwork.customProperties.get(AWS_GATEWAY_ID).equalsIgnoreCase(AWSUtils.NO_VALUE));
    assertTrue(removedNetwork.customProperties.get(AWS_VPC_ROUTE_TABLE_ID).equalsIgnoreCase(AWSUtils.NO_VALUE));
}
Also used : AuthCredentialsServiceState(com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState) ResourcePoolState(com.vmware.photon.controller.model.resources.ResourcePoolService.ResourcePoolState) ProvisionNetworkTaskState(com.vmware.photon.controller.model.tasks.ProvisionNetworkTaskService.ProvisionNetworkTaskState) Operation(com.vmware.xenon.common.Operation) NetworkState(com.vmware.photon.controller.model.resources.NetworkService.NetworkState) Test(org.junit.Test)

Example 3 with ProvisionNetworkTaskState

use of com.vmware.photon.controller.model.tasks.ProvisionNetworkTaskService.ProvisionNetworkTaskState in project photon-model by vmware.

the class TestProvisionAWSNetwork method testInvalidProvisionAWSNetwork.

@Test
public void testInvalidProvisionAWSNetwork() throws Throwable {
    // first create network service
    Operation response = new Operation();
    // create credentials
    Operation authResponse = new Operation();
    TestUtils.postCredentials(this.host, authResponse, this.secretKey, "invalid");
    AuthCredentialsServiceState creds = authResponse.getBody(AuthCredentialsServiceState.class);
    // create resource pool
    Operation poolResponse = new Operation();
    TestUtils.postResourcePool(this.host, poolResponse);
    ResourcePoolState pool = poolResponse.getBody(ResourcePoolState.class);
    NetworkState initialState = TestUtils.buildNetworkState(this.host);
    initialState.authCredentialsLink = creds.documentSelfLink;
    initialState.resourcePoolLink = pool.documentSelfLink;
    initialState.regionId = regionId;
    initialState.instanceAdapterReference = UriUtils.buildUri(ServiceHost.LOCAL_HOST, this.host.getPort(), AWSUriPaths.AWS_NETWORK_ADAPTER, null);
    TestUtils.postNetwork(this.host, initialState, response);
    NetworkState networkState = response.getBody(NetworkState.class);
    // set up network task state
    ProvisionNetworkTaskState task = new ProvisionNetworkTaskState();
    task.requestType = NetworkInstanceRequest.InstanceRequestType.CREATE;
    task.networkDescriptionLink = networkState.documentSelfLink;
    Operation provision = new Operation();
    provisionNetwork(task, provision);
    ProvisionNetworkTaskState ps = provision.getBody(ProvisionNetworkTaskState.class);
    waitForTaskFailure(this.host, UriUtils.buildUri(this.host, ps.documentSelfLink));
}
Also used : AuthCredentialsServiceState(com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState) ResourcePoolState(com.vmware.photon.controller.model.resources.ResourcePoolService.ResourcePoolState) ProvisionNetworkTaskState(com.vmware.photon.controller.model.tasks.ProvisionNetworkTaskService.ProvisionNetworkTaskState) Operation(com.vmware.xenon.common.Operation) NetworkState(com.vmware.photon.controller.model.resources.NetworkService.NetworkState) Test(org.junit.Test)

Example 4 with ProvisionNetworkTaskState

use of com.vmware.photon.controller.model.tasks.ProvisionNetworkTaskService.ProvisionNetworkTaskState in project photon-model by vmware.

the class TestProvisionAWSNetwork method waitForTaskFailure.

private void waitForTaskFailure(VerificationHost host, URI provisioningTaskUri) throws Throwable {
    Date expiration = host.getTestExpiration();
    ProvisionNetworkTaskState provisioningTask;
    do {
        provisioningTask = host.getServiceState(null, ProvisionNetworkTaskState.class, provisioningTaskUri);
        if (provisioningTask.taskInfo.stage == TaskState.TaskStage.FAILED) {
            return;
        }
        Thread.sleep(1000);
    } while (new Date().before(expiration));
    host.log("Pending task:\n%s", Utils.toJsonHtml(provisioningTask));
    throw new TimeoutException("Some tasks never finished");
}
Also used : ProvisionNetworkTaskState(com.vmware.photon.controller.model.tasks.ProvisionNetworkTaskService.ProvisionNetworkTaskState) Date(java.util.Date) TimeoutException(java.util.concurrent.TimeoutException)

Example 5 with ProvisionNetworkTaskState

use of com.vmware.photon.controller.model.tasks.ProvisionNetworkTaskService.ProvisionNetworkTaskState in project photon-model by vmware.

the class TestProvisionAWSNetwork method waitForTaskCompletion.

private void waitForTaskCompletion(VerificationHost host, URI provisioningTaskUri) throws Throwable {
    Date expiration = host.getTestExpiration();
    ProvisionNetworkTaskState provisioningTask;
    do {
        provisioningTask = host.getServiceState(null, ProvisionNetworkTaskState.class, provisioningTaskUri);
        if (provisioningTask.taskInfo.stage == TaskState.TaskStage.FAILED) {
            throw new IllegalStateException("Task failed:" + Utils.toJsonHtml(provisioningTask));
        }
        if (provisioningTask.taskInfo.stage == TaskState.TaskStage.FINISHED) {
            return;
        }
        Thread.sleep(1000);
    } while (new Date().before(expiration));
    host.log("Pending task:\n%s", Utils.toJsonHtml(provisioningTask));
    throw new TimeoutException("Some tasks never finished");
}
Also used : ProvisionNetworkTaskState(com.vmware.photon.controller.model.tasks.ProvisionNetworkTaskService.ProvisionNetworkTaskState) Date(java.util.Date) TimeoutException(java.util.concurrent.TimeoutException)

Aggregations

ProvisionNetworkTaskState (com.vmware.photon.controller.model.tasks.ProvisionNetworkTaskService.ProvisionNetworkTaskState)5 Operation (com.vmware.xenon.common.Operation)3 NetworkState (com.vmware.photon.controller.model.resources.NetworkService.NetworkState)2 ResourcePoolState (com.vmware.photon.controller.model.resources.ResourcePoolService.ResourcePoolState)2 AuthCredentialsServiceState (com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState)2 Date (java.util.Date)2 TimeoutException (java.util.concurrent.TimeoutException)2 Test (org.junit.Test)2