use of com.vmware.photon.controller.model.tasks.ProvisionSecurityGroupTaskService.ProvisionSecurityGroupTaskState in project photon-model by vmware.
the class TestProvisionAWSSecurityGroup method provisionSecurityGroup.
private void provisionSecurityGroup(ProvisionSecurityGroupTaskState ps, Operation response) throws Throwable {
this.host.testStart(1);
Operation startPost = Operation.createPost(this.provisionSecurityGroupFactory).setBody(ps).setCompletion((o, e) -> {
if (e != null) {
this.host.failIteration(e);
return;
}
response.setBody(o.getBody(ProvisionSecurityGroupTaskState.class));
this.host.completeIteration();
});
this.host.send(startPost);
this.host.testWait();
}
use of com.vmware.photon.controller.model.tasks.ProvisionSecurityGroupTaskService.ProvisionSecurityGroupTaskState in project photon-model by vmware.
the class AzureLoadBalancerServiceTest method kickOffSecurityGroupProvision.
private ProvisionSecurityGroupTaskState kickOffSecurityGroupProvision(SecurityGroupInstanceRequest.InstanceRequestType requestType, TaskStage expectedTaskState) throws Throwable {
ProvisionSecurityGroupTaskState taskState = new ProvisionSecurityGroupTaskState();
taskState.requestType = requestType;
taskState.securityGroupDescriptionLinks = Stream.of(securityGroupState.documentSelfLink).collect(Collectors.toSet());
taskState.isMockRequest = this.isMock;
// Start/Post security group provisioning task
taskState = postServiceSynchronously(ProvisionSecurityGroupTaskService.FACTORY_LINK, taskState, ProvisionSecurityGroupTaskState.class);
// Wait for security group provisioning task to complete
return waitForServiceState(ProvisionSecurityGroupTaskState.class, taskState.documentSelfLink, liveState -> expectedTaskState == liveState.taskInfo.stage);
}
use of com.vmware.photon.controller.model.tasks.ProvisionSecurityGroupTaskService.ProvisionSecurityGroupTaskState in project photon-model by vmware.
the class AzureSecurityGroupServiceTest method startSecurityGroupProvisioning.
private ProvisionSecurityGroupTaskState startSecurityGroupProvisioning(InstanceRequestType requestType, SecurityGroupState securityGroupState, TaskStage expectedTaskState) throws Throwable {
ProvisionSecurityGroupTaskState taskState = new ProvisionSecurityGroupTaskState();
taskState.requestType = requestType;
taskState.securityGroupDescriptionLinks = Stream.of(securityGroupState.documentSelfLink).collect(Collectors.toSet());
taskState.isMockRequest = this.isMock;
// Start/Post subnet provisioning task
taskState = postServiceSynchronously(ProvisionSecurityGroupTaskService.FACTORY_LINK, taskState, ProvisionSecurityGroupTaskState.class);
// Wait for provisioning task to complete
return waitForServiceState(ProvisionSecurityGroupTaskState.class, taskState.documentSelfLink, liveState -> expectedTaskState == liveState.taskInfo.stage);
}
use of com.vmware.photon.controller.model.tasks.ProvisionSecurityGroupTaskService.ProvisionSecurityGroupTaskState in project photon-model by vmware.
the class TestProvisionAWSSecurityGroup method testDeleteAWSSecurityGroupWithDependency.
@Test
public void testDeleteAWSSecurityGroupWithDependency() 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));
securityGroupState = getServiceSynchronously(securityGroupState.documentSelfLink, SecurityGroupState.class);
// provision machine on the newly created SG
String vm = provisionAWSVMWithEC2Client(this.host, this.ec2client, EC2_LINUX_AMI, this.subnetId, securityGroupState.id);
// reuse previous task, but switch to a delete
task.requestType = SecurityGroupInstanceRequest.InstanceRequestType.DELETE;
Operation remove = new Operation();
provisionSecurityGroup(task, remove);
// delete the newly provisioned machine after a small delay
Runnable deleteMachine = () -> {
try {
Thread.sleep(2000);
deleteVMsUsingEC2Client(this.ec2client, this.host, Collections.singletonList(vm));
} catch (Throwable t) {
assertNotNull(t);
}
};
deleteMachine.run();
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);
}
}
use of com.vmware.photon.controller.model.tasks.ProvisionSecurityGroupTaskService.ProvisionSecurityGroupTaskState in project photon-model by vmware.
the class TestProvisionAWSSecurityGroup method waitForTaskFailure.
public static void waitForTaskFailure(VerificationHost host, URI provisioningTaskUri) throws Throwable {
Date expiration = host.getTestExpiration();
ProvisionSecurityGroupTaskState provisioningTask;
do {
provisioningTask = host.getServiceState(null, ProvisionSecurityGroupTaskState.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");
}
Aggregations