use of com.vmware.photon.controller.model.resources.ResourcePoolService.ResourcePoolState in project photon-model by vmware.
the class GCPTestUtil method queryComputeStatesWithPowerState.
/**
* Method to query the number of local compute states with given power state.
* @param host The test service host.
* @param resourcePool The default resource pool.
* @param parentCompute The default compute host.
* @param powerState The given power state.
* @param instanceNames The assumed names of compute states.
*/
private static void queryComputeStatesWithPowerState(VerificationHost host, ResourcePoolState resourcePool, ComputeState parentCompute, PowerState powerState, Set<String> instanceNames) {
Query query = QueryTask.Query.Builder.create().addKindFieldClause(ComputeState.class).addFieldClause(ComputeState.FIELD_NAME_RESOURCE_POOL_LINK, resourcePool.documentSelfLink).addFieldClause(ComputeState.FIELD_NAME_PARENT_LINK, parentCompute.documentSelfLink).build();
QueryTask q = QueryTask.Builder.createDirectTask().addOption(QueryTask.QuerySpecification.QueryOption.EXPAND_CONTENT).setQuery(query).build();
host.sendRequest(QueryUtils.createQueryTaskOperation(host, q, ServiceTypeCluster.INVENTORY_SERVICE).setReferer(host.getUri()).setCompletion((o, e) -> {
if (e != null) {
host.log(Level.WARNING, String.format("Error: %s", e.getMessage()));
return;
}
QueryTask queryTask = o.getBody(QueryTask.class);
if (queryTask.results.documentCount > 0) {
queryTask.results.documents.values().forEach(s -> {
ComputeState computeState = Utils.fromJson(s, ComputeState.class);
if (computeState.powerState == powerState) {
instanceNames.remove(computeState.name);
}
});
}
}));
}
use of com.vmware.photon.controller.model.resources.ResourcePoolService.ResourcePoolState in project photon-model by vmware.
the class AzureLifecycleOperationServiceTest method setUp.
@Before
public void setUp() throws Exception {
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);
PhotonModelAdaptersRegistryAdapters.startServices(this.host);
PhotonModelMetricServices.startServices(this.host);
PhotonModelTaskServices.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(1200);
// Create a resource pool where the VM 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);
}
if (!this.isMock) {
ApplicationTokenCredentials credentials = new ApplicationTokenCredentials(this.clientID, this.tenantId, this.clientKey, AzureEnvironment.AZURE);
this.computeManagementClient = new ComputeManagementClientImpl(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 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.resources.ResourcePoolService.ResourcePoolState 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.resources.ResourcePoolService.ResourcePoolState in project photon-model by vmware.
the class LongRunEndToEndStatsAggregationTest 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 = TestAWSSetupUtils.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);
}
Aggregations