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();
}
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));
}
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));
}
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");
}
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");
}
Aggregations