use of com.vmware.photon.controller.model.resources.ResourcePoolService.ResourcePoolState in project photon-model by vmware.
the class TestAzureLongRunningEnumeration method setUp.
@Override
@Before
public void setUp() throws Exception {
for (int i = 0; i < numOfVMsToTest; i++) {
String azureName = generateName(azureVMNamePrefix);
azureVMNames.add(azureName);
nicSpecs.add(initializeNicSpecs(azureName, false, true, false));
}
try {
/*
* Init Class-specific (shared between test runs) vars.
*
* NOTE: Ultimately this should go to @BeforeClass, BUT BasicReusableHostTestCase.HOST
* is not accessible.
*/
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(this.timeoutSeconds);
// Create a resource pool where the VMs will be housed
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);
endpointState.computeHostLink = computeHost.documentSelfLink;
}
this.host.waitForServiceAvailable(PhotonModelServices.LINKS);
this.host.waitForServiceAvailable(PhotonModelTaskServices.LINKS);
this.nodeStatsUri = UriUtils.buildUri(this.host.getUri(), ServiceUriPaths.CORE_MANAGEMENT);
this.maxMemoryInMb = this.host.getState().systemInfo.maxMemoryByteCount / BYTES_TO_MB;
internalTagResourcesMap.put(NetworkState.class, NETWORK_TAG_TYPE_VALUE);
internalTagResourcesMap.put(SubnetState.class, SUBNET_TAG_TYPE_VALUE);
internalTagResourcesMap.put(NetworkInterfaceState.class, NETWORK_INTERFACE_TAG_TYPE_VALUE);
if (!this.isMock) {
ApplicationTokenCredentials credentials = new ApplicationTokenCredentials(this.clientID, this.tenantId, this.clientKey, AzureEnvironment.AZURE);
this.computeManagementClient = new ComputeManagementClientImpl(credentials).withSubscriptionId(this.subscriptionId);
this.resourceManagementClient = new ResourceManagementClientImpl(credentials).withSubscriptionId(this.subscriptionId);
this.storageManagementClient = new StorageManagementClientImpl(credentials).withSubscriptionId(this.subscriptionId);
this.networkManagementClient = new NetworkManagementClientImpl(credentials).withSubscriptionId(this.subscriptionId);
}
} catch (Throwable e) {
throw new Exception(e);
}
}
use of com.vmware.photon.controller.model.resources.ResourcePoolService.ResourcePoolState in project photon-model by vmware.
the class TestAWSEnumerationTask method initResourcePoolAndComputeHost.
/**
* Creates the state associated with the resource pool, compute host and the VM to be created.
*
* @throws Throwable
*/
private 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 = createAWSEndpointState(this.host, auth.documentSelfLink, resourcePool.documentSelfLink);
// create a compute host for the AWS EC2 VM
this.computeHost = createAWSComputeHost(this.host, this.endpointState, null, /*zoneId*/
this.useAllRegions ? null : regionId, this.isAwsClientMock, this.awsMockEndpointReference, null);
this.endpointState.computeHostLink = this.computeHost.documentSelfLink;
this.host.waitForResponse(Operation.createPatch(this.host, this.endpointState.documentSelfLink).setBody(this.endpointState));
}
use of com.vmware.photon.controller.model.resources.ResourcePoolService.ResourcePoolState 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.resources.ResourcePoolService.ResourcePoolState 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);
}
}
use of com.vmware.photon.controller.model.resources.ResourcePoolService.ResourcePoolState in project photon-model by vmware.
the class TestUtils method postResourcePool.
public static void postResourcePool(VerificationHost host, Operation response) throws Throwable {
URI poolFactory = UriUtils.buildUri(host, ResourcePoolService.FACTORY_LINK);
ResourcePoolState pool = new ResourcePoolState();
pool.name = "test-aws";
host.testStart(1);
Operation startPost = Operation.createPost(poolFactory).setBody(pool).setCompletion((o, e) -> {
if (e != null) {
host.failIteration(e);
return;
}
response.setBody(o.getBody(ResourcePoolState.class));
host.completeIteration();
});
host.send(startPost);
host.testWait();
}
Aggregations